isExpanded example


  protected function assertEntity(string $id, string $title, string $menu, ?string $description, bool $enabled, bool $expanded, array $attributes, string $uri, int $weight): void {
    /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
    $menu_link = MenuLinkContent::load($id);
    $this->assertInstanceOf(MenuLinkContentInterface::class$menu_link);
    $this->assertSame($title$menu_link->getTitle());
    $this->assertSame($menu$menu_link->getMenuName());
    $this->assertSame($description$menu_link->getDescription());
    $this->assertSame($enabled$menu_link->isEnabled());
    $this->assertSame($expanded$menu_link->isExpanded());
    $this->assertSame($attributes$menu_link->link->options);
    $this->assertSame($uri$menu_link->link->uri);
    $this->assertSame($weight$menu_link->getWeight());
  }

  /** * Tests migration of menu links. */
  public function testMenuLinks() {
    $this->assertEntity('138', 'Test 1', 'secondary-links', 'Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'Test menu link 1'], 'langcode' => 'en'], 'internal:/user/login', -50);
    $this->assertEntity('139', 'Test 2', 'secondary-links', 'Test menu link 2', TRUE, TRUE, ['query' => ['foo' => 'bar'], 'attributes' => ['title' => 'Test menu link 2']], 'internal:/admin', -49);
    
$form['enabled'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable menu link'),
      '#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'),
      '#default_value' => $this->menuLink->isEnabled(),
    ];

    $form['expanded'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Show as expanded'),
      '#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded. This option may be overridden for the entire menu tree when placing a menu block.'),
      '#default_value' => $this->menuLink->isExpanded(),
    ];

    $menu_parent = $this->menuLink->getMenuName() . ':' . $this->menuLink->getParent();
    $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($menu_parent$this->menuLink->getPluginId());
    $form['menu_parent']['#title'] = $this->t('Parent link');
    $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.');
    $form['menu_parent']['#attributes']['class'][] = 'menu-title-select';

    $delta = max(abs($this->menuLink->getWeight()), 50);
    $form['weight'] = [
      '#type' => 'number',
      
/** * Tests migration of menu links. */
  public function testMenuLinks() {
    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
    $menu_link = MenuLinkContent::load(139)->getTranslation('fr');
    $this->assertInstanceOf(MenuLinkContent::class$menu_link);
    $this->assertSame('fr - Test 2', $menu_link->getTitle());
    $this->assertSame('fr - Test menu link 2', $menu_link->getDescription());
    $this->assertSame('secondary-links', $menu_link->getMenuName());
    $this->assertTrue($menu_link->isEnabled());
    $this->assertTrue($menu_link->isExpanded());
    $this->assertSame(['query' => ['foo' => 'bar'], 'attributes' => ['title' => 'Test menu link 2']]$menu_link->link->options);
    $this->assertSame('internal:/admin', $menu_link->link->uri);
    $this->assertSame(-49, $menu_link->getWeight());

    $menu_link = MenuLinkContent::load(139)->getTranslation('zu');
    $this->assertInstanceOf(MenuLinkContent::class$menu_link);
    $this->assertSame('Test 2', $menu_link->getTitle());
    $this->assertSame('zu - Test menu link 2', $menu_link->getDescription());
    $this->assertSame('secondary-links', $menu_link->getMenuName());
    $this->assertTrue($menu_link->isEnabled());
    $this->assertTrue($menu_link->isExpanded());
    

  protected function assertEntity($id$langcode$title$menu$description$enabled$expanded, array $attributes$uri$weight) {
    /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
    $menu_link = MenuLinkContent::load($id);
    $menu_link = $menu_link->getTranslation($langcode);
    $this->assertInstanceOf(MenuLinkContentInterface::class$menu_link);
    $this->assertSame($title$menu_link->getTitle());
    $this->assertSame($langcode$menu_link->language()->getId());
    $this->assertSame($menu$menu_link->getMenuName());
    $this->assertSame($description$menu_link->getDescription());
    $this->assertSame($enabled$menu_link->isEnabled());
    $this->assertSame($expanded$menu_link->isExpanded());
    $this->assertSame($attributes$menu_link->link->options);
    $this->assertSame($uri$menu_link->link->uri);
    $this->assertSame($weight$menu_link->getWeight());
    return $menu_link;
  }

}

      $definition['options'] = $url_object->getOptions();
    }

    $definition['title'] = $this->getTitle();
    $definition['description'] = $this->getDescription();
    $definition['weight'] = $this->getWeight();
    $definition['id'] = $this->getPluginId();
    $definition['metadata'] = ['entity_id' => $this->id()];
    $definition['form_class'] = '\Drupal\menu_link_content\Form\MenuLinkContentForm';
    $definition['enabled'] = $this->isEnabled() ? 1 : 0;
    $definition['expanded'] = $this->isExpanded() ? 1 : 0;
    $definition['provider'] = 'menu_link_content';
    $definition['discovered'] = 0;
    $definition['parent'] = $this->getParentId();

    return $definition;
  }

  /** * {@inheritdoc} */
  public static function preCreate(EntityStorageInterface $storage, array &$values) {
    


  /** * Tests the generated menu links of views. */
  public function testMenuLinks() {
    \Drupal::service('plugin.manager.menu.link')->rebuild();
    $tree = \Drupal::menuTree()->load('admin', new MenuTreeParameters());
    $this->assertTrue(isset($tree['system.admin']->subtree['views_view:views.test_page_display_menu.page_4']));
    $menu_link = $tree['system.admin']->subtree['views_view:views.test_page_display_menu.page_4']->link;
    $this->assertEquals('Test child (with parent)', $menu_link->getTitle());
    $this->assertEquals(TRUE, $menu_link->isExpanded());
    $this->assertEquals('Sample description.', $menu_link->getDescription());
  }

  /** * Tests the calculated dependencies for various views using Page displays. */
  public function testDependencies() {
    $view = Views::getView('test_page_display');
    $this->assertSame(['module' => ['views_test_data']]$view->getDependencies());

    $view = Views::getView('test_page_display_route');
    
Home | Imprint | This part of the site doesn't use cookies.