public function ModerationDashboardAddLinks::build in Moderation Dashboard 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Block/ModerationDashboardAddLinks.php \Drupal\moderation_dashboard\Plugin\Block\ModerationDashboardAddLinks::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ ModerationDashboardAddLinks.php, line 52
Class
- ModerationDashboardAddLinks
- Provides the "Moderation Dashboard Add Links" block.
Namespace
Drupal\moderation_dashboard\Plugin\BlockCode
public function build() {
$build = [
'#theme' => 'item_list',
'#attributes' => [
'class' => [
'moderation-dashboard-add-links',
],
],
'#items' => [],
];
// Only use node types the user has access to.
$control_handler = $this->entityTypeManager
->getAccessControlHandler('node');
foreach ($this->entityTypeManager
->getStorage('node_type')
->loadMultiple() as $type) {
if ($control_handler
->createAccess($type
->id())) {
$build['#items'][] = [
'#type' => 'link',
'#title' => $type
->label(),
'#url' => new Url('node.add', [
'node_type' => $type
->id(),
]),
];
}
}
return $build;
}