diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuBlockTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuBlockTest.php new file mode 100644 index 0000000..7cd94bf --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuBlockTest.php @@ -0,0 +1,54 @@ + 'Menu block', + 'description' => 'Tests block integration of menus.', + 'group' => 'Menu' + ); + } + + /** + * Tests placing menu blocks. + */ + public function testMenuBlockPlacement() { + // Try editing without block permissions. + $this->drupalLogin($this->drupalCreateUser(array('administer menu'))); + $this->drupalGet('admin/structure/menu'); + $this->clickLink(t('Edit menu')); + $this->assertNoLink(t('Place block')); + + // Place a menu block with proper permissions. + $this->drupalLogin($this->drupalCreateUser(array('administer menu', 'administer blocks'))); + $this->drupalGet('admin/structure/menu'); + $this->clickLink(t('Edit menu')); + // Store the URL used to edit the menu before placing the block. + $menu_edit_url = $this->getUrl(); + $this->clickLink(t('Place block')); + $this->drupalPost(NULL, array(), t('Save block')); + $this->assertText(t('The block configuration has been saved.')); + $this->assertUrl($menu_edit_url, array(), 'After saving the block, the redirect is back to the menu edit page.'); + } + +} diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 57f39b6..f748175 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -11,6 +11,7 @@ * URLs to be added to the main site navigation menu. */ +use Drupal\Component\Utility\Json; use Drupal\Core\Entity\EntityInterface; use Drupal\block\BlockPluginInterface; use Drupal\system\Entity\Menu; @@ -121,6 +122,32 @@ function menu_menu() { } /** + * Implements hook_menu_local_tasks(). + */ +function menu_menu_local_tasks(&$data, $router_item, $root_path) { + if (Drupal::moduleHandler()->moduleExists('block') && $router_item['route_name'] == 'menu_menu_edit') { + // @todo Move to a LocalAction plugin when https://drupal.org/node/2045267 + // allows local actions to work with query strings. + $path = 'admin/structure/block/add/system_menu_block:' . end($router_item['original_map']); + $item = menu_get_item($path); + if ($item['access']) { + $item['localized_options']['query']['destination'] = Drupal::request()->attributes->get('_system_path'); + $item['localized_options']['attributes'] = array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-options' => Json::encode(array( + 'width' => 700, + )), + ); + $data['actions'][$path] = array( + '#theme' => 'menu_local_action', + '#link' => $item, + ); + } + } +} + +/** * Implements hook_entity_info(). */ function menu_entity_info(&$entity_info) {