diff -u b/core/lib/Drupal/Core/Block/BlockOperationsProviderInterface.php b/core/lib/Drupal/Core/Block/BlockOperationsProviderInterface.php --- b/core/lib/Drupal/Core/Block/BlockOperationsProviderInterface.php +++ b/core/lib/Drupal/Core/Block/BlockOperationsProviderInterface.php @@ -14,7 +14,7 @@ /** * Returns a list of operation links available for this block. * - * @return array + * @return array[] * An array of operation links. Keys in this array will overwrite keys of * operations defined in * \Drupal\block\BlockListBuilder::getDefaultOperations(). @@ -24,5 +24,5 @@ * - weight: The link weight. */ - public function getOperationLinks(); + public function getOperationLinks(): array; } diff -u b/core/modules/block/src/BlockInterface.php b/core/modules/block/src/BlockInterface.php --- b/core/modules/block/src/BlockInterface.php +++ b/core/modules/block/src/BlockInterface.php @@ -125,7 +125,7 @@ /** * Returns a list of operation links available for this block. * - * @return array + * @return array[] * An array of operation links. Keys in this array will overwrite keys of * operations defined in * \Drupal\block\BlockListBuilder::getDefaultOperations(). diff -u b/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php --- b/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -366,8 +366,11 @@ $operations['delete']['title'] = $this->t('Remove'); } + // Check for any additional operations. Example edit-view. + // Since these additional operations will take the user away from the + // block layout page, we add a destination parameter to redirect the user + // back. $operation_extras = $entity->getOperationLinks(); - foreach ($operation_extras as $key => $operation_extra) { if ($operation_extra['url']->getOption('query')) { $operation_extra['url']->mergeOptions([ diff -u b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php --- b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php +++ b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php @@ -217,17 +217,19 @@ /** * {@inheritdoc} */ - public function getOperationLinks() { + public function getOperationLinks(): array { $custom_block = $this->getEntity(); $links = []; - // Check the current user has the appropriate permission to edit this + // Check that the current user has the appropriate permission to edit this // custom block. if ($custom_block->access('edit')) { - // Set url options to an empty array as the destination will be set later. $links['block-edit'] = [ 'title' => $this->t('Edit block'), + // Set URL options to an empty array as the destination will be set + // later in \Drupal\block\BlockListBuilder. 'url' => $custom_block->toUrl('edit-form')->setOptions([]), + // Using this weight so this option appears at the top. 'weight' => 50, ]; } diff -u b/core/modules/block_content/tests/src/Kernel/BlockContentTest.php b/core/modules/block_content/tests/src/Kernel/BlockContentTest.php --- b/core/modules/block_content/tests/src/Kernel/BlockContentTest.php +++ b/core/modules/block_content/tests/src/Kernel/BlockContentTest.php @@ -41,7 +41,7 @@ $block_content_type = BlockContentType::create([ 'id' => 'spiffy', 'label' => 'Mucho spiffy', - 'description' => "Provides a block type that increases your site's spiffiness by upto 11%", + 'description' => "Provides a block type that increases your site's spiffiness by up to 11%", ]); $block_content_type->save(); // And a block content entity. @@ -64,12 +64,14 @@ 'weight' => 50, ]; - // Test when user doesn't have "administer block" permission. + // At this point, we are logged in as anonymous, so the user doesn't + // have the "administer block" permission. $this->assertEmpty($links); $this->setUpCurrentUser(['uid' => 1], ['edit any spiffy block content']); $links = $block->getOperationLinks(); - // Test when user does have "administer block" permission. + // At this point, we are logged in as an admin, so the user does + // have the "administer block" permission. $this->assertEquals(['block-edit' => $block_link], $links); } diff -u b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php --- b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php @@ -50,14 +50,14 @@ * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ - protected $moduleHandler; + protected ModuleHandlerInterface $moduleHandler; /** * The current user. * * @var \Drupal\Core\Session\AccountInterface */ - protected $user; + protected AccountInterface $user; /** * Constructs a new SystemMenuBlock. @@ -72,13 +72,22 @@ * The menu tree service. * @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail * The active menu trail service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface|null $module_handler * The module handler used to check whether menu_ui is installed. - * @param \Drupal\Core\Session\AccountInterface $user + * @param \Drupal\Core\Session\AccountInterface|null $user * The current user. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail, ModuleHandlerInterface $module_handler, AccountInterface $user) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail, ModuleHandlerInterface $module_handler = NULL, AccountInterface $user = NULL) { parent::__construct($configuration, $plugin_id, $plugin_definition); + + if (is_null($module_handler)) { + @trigger_error('The SystemMenuBlock constructor now accepts \Drupal\Core\Extension\ModuleHandlerInterface in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3333923.', E_USER_DEPRECATED); + } + + if (is_null($user)) { + @trigger_error('The SystemMenuBlock constructor now accepts \Drupal\Core\Session\AccountInterface in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3333923.', E_USER_DEPRECATED); + } + $this->menuTree = $menu_tree; $this->menuActiveTrail = $menu_active_trail; $this->moduleHandler = $module_handler; @@ -262,7 +271,7 @@ /** * {@inheritdoc} */ - public function getOperationLinks() { + public function getOperationLinks(): array { $menu_name = $this->getDerivativeId(); $links = []; diff -u b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php --- b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -155,7 +155,7 @@ $block = Block::create([ 'plugin' => 'system_menu_block:' . $this->menu->id(), 'region' => 'footer', - 'id' => 'machinename', + 'id' => 'machine_name', 'theme' => 'stark', ]); @@ -181,7 +181,7 @@ $block = Block::create([ 'plugin' => 'system_menu_block:' . $this->menu->id(), 'region' => 'footer', - 'id' => 'machinename', + 'id' => 'machine_name', 'theme' => 'stark', ]); @@ -209,7 +209,7 @@ $place_block = function ($level, $depth) { return $this->blockManager->createInstance('system_menu_block:' . $this->menu->id(), [ 'region' => 'footer', - 'id' => 'machinename', + 'id' => 'machine_name', 'theme' => 'stark', 'level' => $level, 'depth' => $depth, @@ -317,7 +317,7 @@ public function testConfigExpanded($active_route, $menu_block_level, $expected_items) { $block = $this->blockManager->createInstance('system_menu_block:' . $this->menu->id(), [ 'region' => 'footer', - 'id' => 'machinename', + 'id' => 'machine_name', 'theme' => 'stark', 'level' => $menu_block_level, 'depth' => 0, diff -u b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php --- b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php +++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php @@ -249,7 +249,7 @@ /** * {@inheritdoc} */ - public function getOperationLinks() { + public function getOperationLinks(): array { $view = $this->view; $display_id = $this->displayID; $links = []; diff -u b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php --- b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php @@ -170,13 +170,15 @@ 'weight' => 50, ]; - // Test when user doesn't have "administer views" permission. + // At this point, we are logged in as anonymous, so the user doesn't + // have the "administer views" permission. $this->assertEmpty($links); $this->setUpCurrentUser(['uid' => 1], ['administer views']); $links = $block->getOperationLinks(); - // Test when user does have "administer views" permission. + // At this point, we are logged in as an admin, so the user does + // have the "administer views" permission. $this->assertEquals(['view-edit' => $view_link], $links); }