private function createMenus(PageInterface $page, array $menus)
    {
        if (!empty($menus)) {
            foreach ($menus as $parentName => $config) {
                if (null === $parent = $this->menuRepository->findOneByName($parentName)) {
                    $this->output->writeln(sprintf(
                        '<error>Parent menu "%s" not found for route "%s".</error>',
                        $parentName,
                        $page->getRoute()
                    ));

                    return false;
                }

                $name = $page->getRoute();
                if (null === $this->menuRepository->findOneBy(['name' => $name, 'parent' => $parent])) {
                    /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface $menu */
                    $menu = $this->menuRepository->createNew();
                    $menu
                        ->setParent($parent)
                        ->setName($name)
                        ->setRoute($name);

                    if (isset($config['options'])) {
                        $menu->setOptions((array)$config['options']);
                    }
                    if (isset($config['attributes'])) {
                        $menu->setAttributes((array)$config['attributes']);
                    }

                    foreach ($this->locales as $locale) {
                        $menuTranslation = $menu->translate($locale, true);
                        $menuTranslation
                            ->setTitle($page->translate($locale)->getTitle());
                    }

                    if (!$this->validate($menu)) {
                        return false;
                    }

                    $this->menuOperator->persist($menu);
                }
            }
        }

        return true;
    }
private function createMenus(PageInterface $page, array $menus)
    {
        if (!empty($menus)) {
            foreach ($menus as $parentName => $config) {
                if (null === $parent = $this->menuRepository->findOneByName($parentName)) {
                    $this->output->writeln(sprintf(
                        '<error>Parent menu "%s" not found for route "%s".</error>',
                        $parentName,
                        $page->getRoute()
                    ));

                    return false;
                }

                $name = $page->getRoute();
                if (null === $this->menuRepository->findOneBy(['name' => $name, 'parent' => $parent])) {
                    /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface $menu */
                    $menu = $this->menuRepository->createNew();
                    $menu
                        ->setParent($parent)
                        ->setName($name)
                        ->setRoute($name);

                    if (isset($config['options'])) {
                        $menu->setOptions((array)$config['options']);
                    }
                    if (isset($config['attributes'])) {
                        $menu->setAttributes((array)$config['attributes']);
                    }

                    foreach ($this->locales as $locale) {
                        $menuTranslation = $menu->translate($locale, true);
                        $menuTranslation
                            ->setTitle($page->translate($locale)->getTitle());
                    }

                    if (!$this->validate($menu)) {
                        return false;
                    }

                    $this->menuOperator->persist($menu);
                }
            }
        }

        return true;
    }
private function createMenus ( PageInterface $ page , array $ menus ) { if ( ! empty ( $ menus ) ) { foreach ( $ menus as $ parentName => $ config ) { if ( null === $ parent = $ this -> menuRepository -> findOneByName ( $ parentName ) ) { $ this -> output -> writeln ( sprintf ( '<error>Parent menu "%s" not found for route "%s".</error>' , $ parentName , $ page -> getRoute ( ) ) ) ; return false ; } $ name = $ page -> getRoute ( ) ; if ( null === $ this -> menuRepository -> findOneBy ( [ 'name' => $ name , 'parent' => $ parent ] ) ) { /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface $menu */ $ menu = $ this -> menuRepository -> createNew ( ) ; $ menu -> setParent ( $ parent ) -> setName ( $ name ) -> setRoute ( $ name ) ; if ( isset ( $ config [ 'options' ] ) ) { $ menu -> setOptions ( ( array ) $ config [ 'options' ] ) ; } if ( isset ( $ config [ 'attributes' ] ) ) { $ menu -> setAttributes ( ( array ) $ config [ 'attributes' ] ) ; } foreach ( $ this -> locales as $ locale ) { $ menuTranslation = $ menu -> translate ( $ locale , true ) ; $ menuTranslation -> setTitle ( $ page -> translate ( $ locale ) -> getTitle ( ) ) ; } if ( ! $ this -> validate ( $ menu ) ) { return false ; } $ this -> menuOperator -> persist ( $ menu ) ; } } } return true ; }
Creates the menus entries.

@param PageInterface $page
@param array         $menus

@return bool
Creates the menus entries .