diff -u b/src/Plugin/Block/MenuBlock.php b/src/Plugin/Block/MenuBlock.php --- b/src/Plugin/Block/MenuBlock.php +++ b/src/Plugin/Block/MenuBlock.php @@ -35,7 +35,7 @@ const LABEL_ACTIVE_ITEM = 'active_item'; const LABEL_PARENT = 'parent'; const LABEL_ROOT = 'root'; - const LABEL_FIXED_PARENT = 'fixed_parent'; + const LABEL_FIXED = 'fixed'; /** * Entity type manager. @@ -129,7 +129,7 @@ '#options' => [ self::LABEL_BLOCK => $this->t('Block title'), self::LABEL_MENU => $this->t('Menu title'), - self::LABEL_FIXED_PARENT => $this->t("Fixed parent item's title"), + self::LABEL_FIXED => $this->t("Fixed menu item's title"), self::LABEL_ACTIVE_ITEM => $this->t("Active item's title"), self::LABEL_PARENT => $this->t("Active trail's parent title"), self::LABEL_ROOT => $this->t("Active trail's root title"), @@ -407,8 +407,8 @@ case self::LABEL_ROOT: return $this->getActiveTrailRootTitle(); - case self::LABEL_FIXED_PARENT: - return $this->getFixedParentItemTitle(); + case self::LABEL_FIXED: + return $this->getFixedMenuItemTitle(); default: return $this->label(); @@ -439,12 +439,12 @@ * @return string|null * Title of the configured (fixed) parent item, or NULL if there is none. */ - protected function getFixedParentItemTitle() { + protected function getFixedMenuItemTitle() { $parent = $this->configuration['parent']; if ($parent) { - $fixed_parent_menu_link_id = str_replace($this->getDerivativeId() . ':', '', $parent); - return $this->getLinkTitleFromLink($fixed_parent_menu_link_id); + $fixed_menu_link_id = str_replace($this->getDerivativeId() . ':', '', $parent); + return $this->getLinkTitleFromLink($fixed_menu_link_id); } } diff -u b/tests/src/Functional/MenuBlockTest.php b/tests/src/Functional/MenuBlockTest.php --- b/tests/src/Functional/MenuBlockTest.php +++ b/tests/src/Functional/MenuBlockTest.php @@ -472,77 +472,73 @@ 'settings[parent]' => 'main:' . $this->links['child-1'], 'region' => 'primary_menu', ], 'Save block'); - $options = $this->getTestMenuBlockTitltOptions(); - foreach ($options as $option) { - $this->drupalPostForm('admin/structure/block/manage/main', [ - 'settings[label_type]' => $option['option'], - ], 'Save block'); - $test_link = empty($option['test_link']) ? 'menu-block-test/hierarchy/parent/child-1/child-1-1' : $option['test_link']; - $this->drupalGet($test_link); - $this->assertSession()->elementTextContains('css', 'h2#block-main-menu', $option['title']); - } - } - /** - * Provides test data for testMenuBlockTitleOptions(). - */ - protected function getTestMenuBlockTitltOptions() { - return [ - [ + $options = [ + 'block label' => [ 'option' => MenuBlock::LABEL_BLOCK, 'title' => 'Block title', ], - [ + 'menu label' => [ 'option' => MenuBlock::LABEL_MENU, 'title' => 'Main navigation', ], - [ - 'option' => MenuBlock::LABEL_FIXED_PARENT, - 'title' => 'child-1 menu item' + 'fixed menu item' => [ + 'option' => MenuBlock::LABEL_FIXED, + 'title' => 'child-1 menu item', ], - [ - 'option' => MenuBlock::LABEL_FIXED_PARENT, + 'fixed menu item parent' => [ + 'option' => MenuBlock::LABEL_FIXED, 'title' => 'child-1 menu item', - 'test_link' => 'menu-block-test/hierarchy/parent' + 'test_link' => 'menu-block-test/hierarchy/parent', ], - [ + 'active item' => [ 'option' => MenuBlock::LABEL_ACTIVE_ITEM, 'title' => 'child-1-1 menu item', ], - [ + 'parent item' => [ 'option' => MenuBlock::LABEL_PARENT, 'title' => 'child-1 menu item', ], - [ + 'parent item top level' => [ + 'option' => MenuBlock::LABEL_PARENT, + 'title' => 'parent menu item', + 'test_link' => 'menu-block-test/hierarchy/parent', + ], + 'parent item 2' => [ 'option' => MenuBlock::LABEL_PARENT, 'title' => 'parent menu item', 'test_link' => 'menu-block-test/hierarchy/parent/child-1', ], - [ + 'parent item 3' => [ 'option' => MenuBlock::LABEL_PARENT, 'title' => 'child-1 menu item', 'test_link' => 'menu-block-test/hierarchy/parent/child-1/child-1-2', ], - [ - 'option' => MenuBlock::LABEL_PARENT, - 'title' => 'parent menu item', - 'test_link' => 'menu-block-test/hierarchy/parent', - ], - [ + 'menu root' => [ 'option' => MenuBlock::LABEL_ROOT, - 'title' => 'parent menu item' + 'title' => 'parent menu item', ], - [ + 'menu root 2' => [ 'option' => MenuBlock::LABEL_ROOT, 'title' => 'parent menu item', - 'test_link' => 'menu-block-test/hierarchy/parent/child-1/child-1-2', + 'test_link' => 'menu-block-test/hierarchy/parent/child-1', ], - [ + 'menu root 3' => [ 'option' => MenuBlock::LABEL_ROOT, 'title' => 'parent menu item', - 'test_link' => 'menu-block-test/hierarchy/parent/child-1', + 'test_link' => 'menu-block-test/hierarchy/parent/child-1/child-1-2', ], ]; + + foreach ($options as $option) { + $this->drupalPostForm('admin/structure/block/manage/main', [ + 'settings[label_type]' => $option['option'], + ], 'Save block'); + $test_link = empty($option['test_link']) ? 'menu-block-test/hierarchy/parent/child-1/child-1-1' : $option['test_link']; + $this->drupalGet($test_link); + $this->assertSession() + ->elementTextContains('css', 'h2#block-main-menu', $option['title']); + } } }