class ForumBlockBase
Same name in other branches
- 9 core/modules/forum/src/Plugin/Block/ForumBlockBase.php \Drupal\forum\Plugin\Block\ForumBlockBase
- 10 core/modules/forum/src/Plugin/Block/ForumBlockBase.php \Drupal\forum\Plugin\Block\ForumBlockBase
- 11.x core/modules/forum/src/Plugin/Block/ForumBlockBase.php \Drupal\forum\Plugin\Block\ForumBlockBase
Provides a base class for Forum blocks.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\forum\Plugin\Block\ForumBlockBase extends \Drupal\Core\Block\BlockBase
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
Expanded class hierarchy of ForumBlockBase
File
-
core/
modules/ forum/ src/ Plugin/ Block/ ForumBlockBase.php, line 15
Namespace
Drupal\forum\Plugin\BlockView source
abstract class ForumBlockBase extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$result = $this->buildForumQuery()
->execute();
$elements = [];
if ($node_title_list = node_title_list($result)) {
$elements['forum_list'] = $node_title_list;
$elements['forum_more'] = [
'#type' => 'more_link',
'#url' => Url::fromRoute('forum.index'),
'#attributes' => [
'title' => $this->t('Read the latest forum topics.'),
],
];
}
return $elements;
}
/**
* Builds the select query to use for this forum block.
*
* @return \Drupal\Core\Database\Query\Select
* A Select object.
*/
protected abstract function buildForumQuery();
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'properties' => [
'administrative' => TRUE,
],
'block_count' => 5,
];
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'access content');
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$range = range(2, 20);
$form['block_count'] = [
'#type' => 'select',
'#title' => $this->t('Number of topics'),
'#default_value' => $this->configuration['block_count'],
'#options' => array_combine($range, $range),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['block_count'] = $form_state->getValue('block_count');
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return Cache::mergeContexts(parent::getCacheContexts(), [
'user.node_grants:view',
]);
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), [
'node_list',
]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ForumBlockBase::blockAccess | protected | function | ||
ForumBlockBase::blockForm | public | function | ||
ForumBlockBase::blockSubmit | public | function | ||
ForumBlockBase::build | public | function | ||
ForumBlockBase::buildForumQuery | abstract protected | function | Builds the select query to use for this forum block. | 2 |
ForumBlockBase::defaultConfiguration | public | function | ||
ForumBlockBase::getCacheContexts | public | function | ||
ForumBlockBase::getCacheTags | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.