function MenuUiHooks::entityOperation

Implements hook_entity_operation().

File

core/modules/menu_ui/src/Hook/MenuUiHooks.php, line 282

Class

MenuUiHooks
Hook implementations for menu_ui.

Namespace

Drupal\menu_ui\Hook

Code

public function entityOperation(EntityInterface $entity) : array {
    $operations = [];
    if ($entity instanceof BlockInterface) {
        $plugin = $entity->getPlugin();
        if ($plugin->getBaseId() === 'system_menu_block') {
            $menu = Menu::load($plugin->getDerivativeId());
            if ($menu && $menu->access('edit')) {
                $operations['menu-edit'] = [
                    'title' => t('Edit menu'),
                    'url' => $menu->toUrl('edit-form'),
                    'weight' => 50,
                ];
            }
        }
    }
    return $operations;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.