Verified Commit 22add58e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3411384 by phthlaap, venkatadapa, alecsmrekar, plach, alexpott, heddn,...

Issue #3411384 by phthlaap, venkatadapa, alecsmrekar, plach, alexpott, heddn, Graber: Error: Call to a member function label() on null in Drupal\menu_link_content\Form\MenuLinkContentForm->form() (line 99 of /var/www/html/docroot/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php)

(cherry picked from commit 84432de2)
parent 2839eeca
Loading
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\system\MenuInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -92,9 +93,9 @@ public function form(array $form, FormStateInterface $form_state) {
    $parent_id = $this->entity->getParentId() ?: $this->getRequest()->query->get('parent');
    $default = $this->entity->getMenuName() . ':' . $parent_id;
    $id = $this->entity->isNew() ? '' : $this->entity->getPluginId();
    if ($this->entity->isNew()) {
    $menu_id = $this->entity->getMenuName();
    $menu = $this->entityTypeManager->getStorage('menu')->load($menu_id);
    if ($menu instanceof MenuInterface && $this->entity->isNew()) {
      $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $id, [
        $menu_id => $menu->label(),
      ]);
+16 −0
Original line number Diff line number Diff line
@@ -459,4 +459,20 @@ public function testMenuLinkContentGetEntity(): void {
    $this->assertEquals($menu_link->id(), $tree_element->link->getEntity()->id());
  }

  /**
   * Tests that the form doesn't break for links with arbitrary menu names.
   */
  public function testMenuLinkContentFormInvalidParentMenu(): void {
    $menu_link = MenuLinkContent::create([
      'title' => 'Menu link test',
      'provider' => 'menu_link_content',
      'menu_name' => 'non-existent',
      'link' => ['uri' => 'internal:/user/login'],
    ]);
    // Get the form for a new link, assert that building it doesn't break if
    // the links menu name doesn't exist.
    $build = \Drupal::service('entity.form_builder')->getForm($menu_link);
    static::assertIsArray($build);
  }

}