diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 7d66cf4..237c1b8 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -562,4 +562,11 @@ protected function contextHandler() { return \Drupal::service('context.handler'); } + /** + * {@inheritdoc} + */ + public function getOperationLinks() { + return array(); + } + } diff --git a/core/lib/Drupal/Core/Block/BlockPluginInterface.php b/core/lib/Drupal/Core/Block/BlockPluginInterface.php index 200d10d..a25486f 100644 --- a/core/lib/Drupal/Core/Block/BlockPluginInterface.php +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php @@ -12,6 +12,7 @@ use Drupal\Core\Cache\CacheableInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Core\Entity\OperationsProviderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Session\AccountInterface; @@ -26,7 +27,7 @@ * * @ingroup block_api */ -interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface, CacheableInterface, DerivativeInspectionInterface { +interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface, CacheableInterface, DerivativeInspectionInterface, OperationsProviderInterface { /** * Returns the user-facing block label. diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index ba7380a..fb62145 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -547,4 +547,11 @@ public function toArray() { return array(); } + /** + * {@inheritdoc} + */ + public function getOperationLinks() { + return array(); + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 4399d01..06ef6bd 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -12,7 +12,7 @@ /** * Defines a common interface for all entity objects. */ -interface EntityInterface extends AccessibleInterface { +interface EntityInterface extends AccessibleInterface, OperationsProviderInterface { /** * Returns the entity UUID (Universally Unique Identifier). diff --git a/core/lib/Drupal/Core/Entity/OperationsProviderInterface.php b/core/lib/Drupal/Core/Entity/OperationsProviderInterface.php new file mode 100644 index 0000000..bc873e0 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/OperationsProviderInterface.php @@ -0,0 +1,23 @@ +getOperationLinks(); + return $operations; } diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php index ee977d0..d09a7fc 100644 --- a/core/modules/block/src/Entity/Block.php +++ b/core/modules/block/src/Entity/Block.php @@ -174,4 +174,13 @@ public function getVisibility() { return $this->getPlugin()->getVisibilityConditions()->getConfiguration(); } + /** + * {@inheritdoc} + */ + public function getOperationLinks() { + $plugin = $this->getPlugin(); + $links = $plugin->getOperationLinks(); + return $links; + } + } diff --git a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php index dd4c6ad..748a4f5 100644 --- a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php @@ -12,6 +12,8 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Menu\MenuActiveTrailInterface; use Drupal\Core\Menu\MenuLinkTreeInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -134,4 +136,22 @@ protected function getRequiredCacheContexts() { return array('cache_context.user.roles', 'cache_context.language'); } + /** + * {@inheritdoc} + */ + public function getOperationLinks() { + $menu = $this->getDerivativeId(); + + $links = array(); + $links['menu-edit'] = array( + 'title' => $this->t('Edit menu'), + 'route_name' => 'entity.menu.edit_form', + 'route_parameters' => array( + 'menu' => $menu, + ), + 'weight' => 50, + ); + return $links; + } + } diff --git a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php index 80c3d3d..e7bc012 100644 --- a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php +++ b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php @@ -6,6 +6,8 @@ namespace Drupal\system\Tests\Block; use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\user\Entity\Role; +use Drupal\user\Entity\User; /** * Tests \Drupal\system\Plugin\Block\SystemMenuBlock. @@ -24,7 +26,24 @@ class SystemMenuBlockTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system', 'block'); + public static $modules = array('system', 'block', 'user'); + + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('user'); + $user = User::create(array( + 'name' => 'tony', + 'mail' => 'tony@magicalponies.com', + )); + $role = Role::create(array( + 'label' => 'Menu manager', + 'id' => 'menu_manager', + )); + $role->grantPermission('administer menu'); + $role->save(); + $user->addRole($role->id()); + \Drupal::service('current_user')->setAccount($user); + } /** * Tests calculation of a system menu block's configuration dependencies. @@ -61,5 +80,14 @@ public function testSystemMenuBlockConfigDependencies() { ), ); $this->assertIdentical($expected, $dependencies); + + $links = $block->getOperationLinks(); + $menu_link = array( + 'title' => 'Edit menu', + 'route_name' => 'menu_ui.menu_edit', + 'route_parameters' => array('menu' => $menu_name), + 'weight' => 50, + ); + $this->assertIdentical($links, ['menu-edit' => $menu_link]); } } diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 51e16b2..f29ae6d 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -1125,4 +1125,11 @@ public function getListCacheTags() { $this->storage->getListCacheTags(); } + /** + * {@inheritdoc} + */ + public function getOperationLinks() { + return $this->storage->getOperationLinks(); + } + }