WorkbenchBlock.php in Workbench 8
Namespace
Drupal\workbench\Plugin\BlockFile
src/Plugin/Block/WorkbenchBlock.phpView source
<?php
namespace Drupal\workbench\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;
/**
* Register a block that other modules may hook into.
*
* @Block(
* id = "workbench_block",
* admin_label = @Translation("Workbench information")
* )
*/
class WorkbenchBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$items = \Drupal::moduleHandler()
->invokeAll('workbench_block');
if (empty($items)) {
return [];
}
return [
'#markup' => '<div class="workbench-info-block">' . implode('<br />', $items) . '</div>',
'#attached' => [
'library' => [
'workbench/workbench.block',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'access workbench');
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [
'url.path',
];
}
}
Classes
Name | Description |
---|---|
WorkbenchBlock | Register a block that other modules may hook into. |