createMenuItem example

throw new InvalidArgumentException('Root Menu Item must provide parent element');
                }

                /** @var Menu $parent */
                $parent = $this->menuRepository->findOneBy($menuItem['parent']);

                if (!\is_object($parent)) {
                    throw new InvalidArgumentException(sprintf('Unable to find parent for query %s', print_r($menuItem['parent'], true)));
                }
            }

            $items[] = $this->createMenuItem($menuItem$parent);
        }

        $this->em->flush($items);
        $this->removeNotExistingEntries($contentTypes);
        $this->cleanupContentTypeEntries();
    }

    protected function createMenuItem(array $menuItem, ?Menu $parent = null): Menu
    {
        $item = null;

        
$permissions = ['view own unpublished content'];
    $this->authorAccount = $this->setUpCurrentUser([
      'name' => 'author',
      'pass' => 'authorPass',
    ]$permissions);

    NodeType::create([
      'type' => 'page',
    ])->save();

    $home_page_link = $this->createMenuItem([
      'title' => 'Home',
      'description' => 'Links to the home page.',
      'link' => 'internal:/<front>',
      'weight' => 0,
      'menu_name' => 'main',
    ]);

    $about_us_page = $this->createNode([
      'nid' => 1,
      'title' => 'About us',
      'type' => 'page',
      

        $this->subscribeEvent(
            'Enlight_Controller_Action_PostDispatch_Backend_Index',
            'onBackendIndexPostDispatch'
        );

        $this->subscribeEvent(
            'Enlight_Controller_Dispatcher_ControllerPath_Backend_SwagUpdate',
            'onGetSwagUpdateControllerPath'
        );

        $this->createMenuItem([
            'label' => 'SwagUpdate',
            'controller' => 'SwagUpdate',
            'class' => 'sprite-arrow-continue-090',
            'action' => 'Index',
            'active' => 1,
            'parent' => $this->Menu()->findOneBy(['id' => 40]), // help menu         ]);

        return ['success' => true, 'invalidateCache' => ['backend']];
    }

    
$parent = null;
            } else {
                if (!isset($menuItem['parent'])) {
                    throw new InvalidArgumentException('Root Menu Item must provide parent element');
                }
                $parent = $this->menuRepository->findOneBy($menuItem['parent']);
                if (!$parent) {
                    throw new InvalidArgumentException(sprintf('Unable to find parent for query %s', print_r($menuItem['parent'], true)));
                }
            }

            $items[] = $this->createMenuItem($plugin$parent$menuItem);
        }

        $this->em->flush($items);
        $this->removeNotExistingEntries($plugin->getId()$menuNames);
    }

    private function saveMenuTranslation(array $labels, string $name): void
    {
        $databaseWriter = new DatabaseWriter($this->em->getConnection());
        foreach ($labels as $locale => $text) {
            if ($locale === 'en') {
                
$this->drupalLogout();

    $permissions = [
      'view own unpublished content',
    ];
    $this->authorAccount = $this->setUpCurrentUser([
      'name' => 'author',
      'pass' => 'authorPass',
    ]$permissions);

    // Generate some data which we can test against.     $home_page_link = $this->createMenuItem([
      'title' => 'Home',
      'description' => 'Links to the home page.',
      'link' => 'internal:/<front>',
      'weight' => 0,
      'menu_name' => 'main',
    ]);

    // Multilingual test.     $multi_lingual_node = $this->createNode([
      'nid' => 1,
      'title' => 'A multi-lingual-node',
      
Home | Imprint | This part of the site doesn't use cookies.