public function AddContentMenu::buildRenderArray in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Dashboard/AddContentMenu.php \Drupal\dashboards\Plugin\Dashboard\AddContentMenu::buildRenderArray()
Build render array.
Parameters
array $configuration: Plugin configuration.
Return value
array Return render array.
Overrides DashboardBase::buildRenderArray
File
- src/
Plugin/ Dashboard/ AddContentMenu.php, line 75
Class
- AddContentMenu
- Show account info.
Namespace
Drupal\dashboards\Plugin\DashboardCode
public function buildRenderArray($configuration) : array {
$bundleInfo = $this->bundleInfo
->getBundleInfo('node');
$items = [];
foreach ($configuration['items'] as $bundle => $info) {
if (AccessResult::allowedIfHasPermission($this->account, 'create ' . $bundle . ' content')
->isAllowed()) {
$items[] = [
'#type' => 'link',
'#url' => Url::fromRoute('node.add', [
'node_type' => $bundle,
]),
'#title' => $bundleInfo[$bundle]['label'],
];
}
}
return [
'menu' => [
'#theme' => 'item_list',
'#items' => $items,
'#attributes' => [
'class' => [
'dashboard-create-content-links',
],
],
],
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
}