public function SeedsManager::buildMenu in Seeds Toolbar 8
Build "Add" menu item.
File
- src/
SeedsManager.php, line 62
Class
- SeedsManager
- Helper function for SeedsToolbar.
Namespace
Drupal\seeds_toolbarCode
public function buildMenu($entity_type, $route) {
// Seeds toolbar should not depend on any entity type, se we check if the entity type exists or not.
if ($this->entityTypeManager
->hasDefinition($entity_type)) {
$entities = $this->entityTypeManager
->getStorage($entity_type)
->loadMultiple();
}
else {
return [];
}
$items = [];
foreach ($entities as $entity) {
$id = $entity
->id();
$url = Url::fromRoute($route, [
$entity_type => $id,
]);
// Block content are a special case, so we want to handle it.
if ($entity_type == 'block_content_type') {
$access = $this
->handleBlockPermission($entity);
}
else {
$access = $this
->userHasAccess($url);
}
if ($access) {
$items[$id] = Link::fromTextAndUrl($entity
->label(), $url);
}
}
if (empty($items)) {
return [];
}
else {
return [
'#menu_name' => $entity_type . '-add-menu',
'#items' => $items,
'#theme' => 'seeds_add_menu',
];
}
}