Verified Commit 6884ce47 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #2703349 Show as expanded checkbox is not necessary when No menu entry is selected

By: peri22
By: larowlan
By: smustgrave
By: sonam.chaturvedi
By: saman_malik
(cherry picked from commit b0128a3a)
parent 0e52dc99
Loading
Loading
Loading
Loading
Loading
+7
Changes for core/modules/views/src/Plugin/views/display/Page.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -339,6 +339,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
          '#type' => 'checkbox',
          '#default_value' => !empty($menu['expanded']),
          '#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded.'),
          // Only normal menu links end up in a menu and can be expanded.
          // @see \Drupal\views\Plugin\views\display\PathPluginBase::getMenuLinks()
          '#states' => [
            'visible' => [
              ':input[name="menu[type]"]' => ['value' => 'normal'],
            ],
          ],
        ];

        $menu_parent = $menu['menu_name'] . ':' . $menu['parent'];
+29
Changes for core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -89,6 +89,35 @@ public function testAddDisplay(): void {
    $this->assertNotEmpty($element);
  }

  /**
   * Tests that "Show as expanded" only shows for a normal menu entry.
   */
  public function testMenuExpandedVisibility(): void {
    $this->drupalGet('admin/structure/views/view/test_content_ajax/edit/page_1');
    $page = $this->getSession()->getPage();

    // Open the menu settings of the page display.
    $page->find('css', 'a[href*="/display/test_content_ajax/page_1/menu"]')->click();
    $expanded = $this->assertSession()->waitForField('menu[expanded]');

    // The display is a menu tab, which never ends up in a menu.
    $this->assertFalse($expanded->isVisible());

    // A normal menu link can have children to expand.
    $page->find('css', 'input[name="menu[type]"][value="normal"]')->click();
    $page->waitFor(10, function () use ($expanded) {
      return $expanded->isVisible();
    });
    $this->assertTrue($expanded->isVisible());

    // Without a menu entry there is nothing to expand.
    $page->find('css', 'input[name="menu[type]"][value="none"]')->click();
    $page->waitFor(10, function () use ($expanded) {
      return !$expanded->isVisible();
    });
    $this->assertFalse($expanded->isVisible());
  }

  /**
   * Tests setting the administrative title.
   */