New material entity creation controller action
@param int $navigation Parent navigation identifier
193915
public function __new($navigation = array())
    {
        // Create new entity
        $entity = new Material();
        $entity->Active = 1;
        $entity->Created = date('Y-m-d H:m:s');

        // Set user
        $user = $this->system->module('social')->user();

        if (isset($user->user_id)) {
            $entity->UserID = $user->userId;
        }
        else {
            $entity->UserID = '1';
        }

        // Persist
        $entity->save();

        // Set name for created material
        $entity->Name = t($this->name, true).' №'.$entity->id;
        $entity->Url = utf8_translit($entity->Name);

        // Check unique url for material
        if ($this->query->entity(Material::class)->where(Material::F_IDENTIFIER, utf8_translit($entity->Name))->first()) {
            $entity->Url = md5(utf8_translit($entity->Name));
        }

        // Persist
        $entity->save();

        Event::fire('samsoncms.app.material.new', array(&$entity));

        $navigation = is_array($navigation) ? $navigation : array($navigation);

        // Set navigation relation
        foreach (array_merge($navigation, static::$structures) as $structureID) {
            // Create relation with structure
            $structureMaterial = new NavigationMaterial();
            $structureMaterial->MaterialID = $entity->id;
            $structureMaterial->StructureID = $structureID;
            $structureMaterial->Active = '1';
            $structureMaterial->save();
        }

        // Go to correct form URL
        url()->redirect($this->system->module('cms')->baseUrl . '/' . $this->id . '/form/' . $entity->id);
    }
475954
private function buildExtensionsNavigation(&$nav)
    {
        // Loop over all the installed extensions to add in other navigation items
        $extensions = Symphony::ExtensionManager()->listInstalledHandles();

        foreach ($extensions as $e) {
            $extension = Symphony::ExtensionManager()->getInstance($e);
            $extension_navigation = $extension->fetchNavigation();

            if (is_array($extension_navigation) && !empty($extension_navigation)) {
                foreach ($extension_navigation as $item) {
                    $type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;

                    switch ($type) {
                        case Extension::NAV_GROUP:
                            $index = General::array_find_available_index($nav, $item['location']);

                            // Actual group
                            $nav[$index] = self::createParentNavItem($index, $item);

                            // Render its children
                            foreach ($item['children'] as $child) {
                                $nav[$index]['children'][] = self::createChildNavItem($child, $e);
                            }

                            break;

                        case Extension::NAV_CHILD:
                            if (!is_numeric($item['location'])) {
                                // is a navigation group
                                $group_name = $item['location'];
                                $group_index = self::__navigationFindGroupIndex($nav, $item['location']);
                            } else {
                                // is a legacy numeric index
                                $group_index = $item['location'];
                            }

                            $child = self::createChildNavItem($item, $e);

                            if ($group_index === false) {
                                $group_index = General::array_find_available_index($nav, 0);

                                $nav_parent = self::createParentNavItem($group_index, $item);
                                $nav_parent['name'] = $group_name;
                                $nav_parent['children'] = array($child);

                                // add new navigation group
                                $nav[$group_index] = $nav_parent;
                            } else {
                                // add new location by index
                                $nav[$group_index]['children'][] = $child;
                            }

                            break;
                    }
                }
            }
        }
    }
668463
public function extend_course_navigation($navigation, navigation_node $node) {
        // Display orphaned activities for the users who can see them.
        $context = context_course::instance($this->courseid);
        if (has_capability('moodle/course:viewhiddensections', $context)) {
            $modinfo = get_fast_modinfo($this->courseid);
            if (!empty($modinfo->sections[1])) {
                $section1 = $modinfo->get_section_info(1);
                // Show orphaned activities.
                $orphanednode = $node->add(get_string('orphaned', 'format_singleactivity'),
                        $this->get_view_url(1), navigation_node::TYPE_SECTION, null, $section1->id);
                $orphanednode->nodetype = navigation_node::NODETYPE_BRANCH;
                $orphanednode->add_class('orphaned');
                foreach ($modinfo->sections[1] as $cmid) {
                    if (has_capability('moodle/course:viewhiddenactivities', context_module::instance($cmid))) {
                        $this->navigation_add_activity($orphanednode, $modinfo->cms[$cmid]);
                    }
                }
            }
        }
    }
240615
public function __async_form($parentID = 0, $navID = 0)
    {
        /** @var CMSNav $data */
        $data = null;

        if (dbQuery('\samson\cms\web\navigation\CMSNav')->StructureID($navID)->first($data)) {
            if (dbQuery('\samson\cms\CMSMaterial')->id($data->MaterialID)->first($mat)) {
                m()->cmsmaterial($mat);
            }
            $parent_id = $parentID;
        } else {
            $parent_id = 0;
            if (dbQuery('\samson\cms\web\navigation\CMSNav')->id($parentID)->first($nav)) {
                if (isset($nav->parent()->id)) {
                    $parent_id = $nav->parent()->id;
                }
            }
        }

        // Render form
        $html = m()->view('form/form')
            ->parent_select(CMSNav::createSelect($parentID))
            ->cmsnav($data)
            ->parent_id($parent_id)
            ->output();

        return array(
            'status'=>1,
            'html'=>$html
        );
    }
285473
private function createPage(RouteDefinition $definition, PageInterface $parentPage = null)
    {
        $routeName = $definition->getRouteName();
        if (null !== $page = $this->findPageByRouteName($routeName)) {

            $updated = false;
            if ($page->getName() !== $definition->getPageName()) {
                $page->setName($definition->getPageName());
                $updated = true;
            }
            if ($page->isLocked() !== $definition->isLocked()) {
                $page->setLocked($definition->isLocked());
                $updated = true;
            }
            if ($page->isAdvanced() !== $definition->isAdvanced()) {
                $page->setAdvanced($definition->isAdvanced());
                $updated = true;
            }
            if ($page->isDynamicPath() !== $definition->isDynamic()) {
                $page->setDynamicPath($definition->isDynamic());
                $updated = true;
            }

            // Watch for paths update
            foreach ($this->locales as $locale) {
                if ($routeName === $path = $this->translator->trans(
                        $routeName, [], $this->routesTranslationDomain, $locale
                    )
                ) {
                    $path = $definition->getPath();
                }

                $pageTranslation = $page->translate($locale, true);
                if ($pageTranslation->getPath() !== $path) {
                    $pageTranslation->setPath($path);
                    $updated = true;
                }
            }

            if ($updated) {
                if (!$this->validate($page)) {
                    return false;
                }
                $this->pageOperator->persist($page);
            }

            $this->outputPageAction($page->getName(), $updated ? 'updated' : 'already exists');

        } else {
            /** @var PageInterface $page */
            $page = $this->pageRepository->createNew();

            // Seo
            $seoDefinition = $definition->getSeo();
            /** @var SeoInterface $seo */
            $seo = $this->seoRepository->createNew();
            $seo
                ->setChangefreq($seoDefinition['changefreq'])
                ->setPriority($seoDefinition['priority'])
                ->setFollow($seoDefinition['follow'])
                ->setIndex($seoDefinition['index'])
                ->setCanonical($seoDefinition['canonical']);

            // Page
            $page
                ->setName($definition->getPageName())
                ->setRoute($routeName)
                ->setPath($definition->getPath())
                ->setStatic(true)
                ->setLocked($definition->isLocked())
                ->setAdvanced($definition->isAdvanced())
                ->setParent($parentPage)
                ->setSeo($seo);

            $dynamic = false;
            foreach ($this->locales as $locale) {
                $title = $seoTitle = $definition->getPageName();
                if (null !== $parentPage && $parentPage->getRoute() !== $this->homeRouteName) {
                    $seoTitle = sprintf('%s - %s', $parentPage->getSeo()->translate($locale)->getTitle(), $title);
                }

                $seoTranslation = $seo->translate($locale, true);
                $seoTranslation
                    ->setTitle($seoTitle);

                if ($routeName === $path = $this->translator->trans(
                        $routeName, [], $this->routesTranslationDomain, $locale
                    )
                ) {
                    $path = $definition->getPath();
                }

                $pageTranslation = $page->translate($locale, true);
                $pageTranslation
                    ->setTitle($title)
                    ->setBreadcrumb($title)
                    ->setPath($path);

                if (0 < preg_match('~\{.*\}~', $path)) {
                    $dynamic = true;
                }
            }

            if ($dynamic != $page->isDynamicPath()) {
                $page->setDynamicPath($dynamic);
            }

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

            $this->pageOperator->persist($page);

            $this->outputPageAction($page->getName(), 'created');
        }

        if (!$this->createMenus($page, $definition->getMenus())) {
            return false;
        }

        // Creates children pages
        foreach ($definition->getChildren() as $child) {
            if (!$this->createPage($child, $page)) {
                return false;
            }
        }

        return true;
    }
1307319
public function createAction(Request $request)
    {
        $entity = new Menu();
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            /* set root item */
            $rootItem = new MenuItem();
            $rootItem->setName($entity->getName()." Root Item");
            $rootItem->setIsRoot(true);
            $rootItem->setMenu($entity);
            $em->persist($rootItem);
            $em->flush();

            return $this->redirect($this->generateUrl('admin_menu_show', array('id' => $entity->getId())));
        }

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
626269
public function find($navigationItem)
    {
        $stack = [$this];
        while (!empty($stack)) {
            /** @var NavigationItem $item */
            $item = array_pop($stack);
            if ($item->equalsChildless($navigationItem)) {
                return $item;
            }
            foreach ($item->getChildren() as $child) {
                /* @var NavigationItem $child */
                $stack[] = $child;
            }
        }

        return;
    }
750849
private function applyNavigations(Siteroot $siteroot, array $data)
    {
        if (!array_key_exists('navigations', $data)) {
            // noting to save
            return $this;
        }

        $navigationData = $data['navigations'];

        foreach ($navigationData['created'] as $row) {
            $navigation = new Navigation();
            $navigation
                ->setSiteroot($siteroot)
                ->setAdditional(!empty($row['additional']) ? $row['additional'] : null)
                ->setFlags($row['flags'])
                ->setStartTreeId($row['start_tid'])
                ->setTitle($row['title'])
                ->setMaxDepth($row['max_depth']);

            $siteroot->addNavigation($navigation);
        }

        foreach ($navigationData['modified'] as $row) {
            foreach ($siteroot->getNavigations() as $navigation) {
                if ($navigation->getId() === $row['id']) {
                    $navigation
                        ->setSiteroot($siteroot)
                        ->setAdditional(!empty($row['additional']) ? $row['additional'] : null)
                        ->setFlags($row['flags'])
                        ->setStartTreeId($row['start_tid'])
                        ->setTitle($row['title'])
                        ->setMaxDepth($row['max_depth']);

                    break;
                }
            }
        }

        foreach ($navigationData['deleted'] as $id) {
            foreach ($siteroot->getNavigations() as $navigation) {
                if ($navigation->getId() === $id) {
                    $siteroot->removeNavigation($navigation);
                    break;
                }
            }
        }

        return $this;
    }
734022
public function navigation_tree(global_navigation $navigation, $expansionlimit, array $options = array()) {
        $navigation->add_class('navigation_node');
        $navigationattrs = array(
            'class' => 'block_tree list',
            'role' => 'tree',
            'data-ajax-loader' => 'block_navigation/nav_loader');
        $content = $this->navigation_node(array($navigation), $navigationattrs, $expansionlimit, $options);
        if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) {
            $content = $this->output->box($content, 'block_tree_box', $navigation->id);
        }
        return $content;
    }
397161
public function createAction()
    {
        if ($this->enableScreens) {
            $edit = false;
            $org  = $this->getRespondent()->getOrganization();
            if (! $org) {
                $org = $this->currentOrganization;
            }

            if ($org) {
                $edit = $org->getRespondentEditScreen();
            }

            if (! $edit) {
                $group = $this->currentUser->getGroup();
                if ($group) {
                    $edit = $group->getRespondentEditScreen();
                }
            }

            if ($edit ) {
                if ($edit instanceof ProcessModelInterface) {
                    $edit->processModel($this->getModel());
                }

                // All are arrays, so easy to set
                $this->createParameters = $edit->getCreateParameters() + $this->createParameters;
                $editSnippets = $edit->getSnippets();
                if (false !== $editSnippets) {
                    $this->createEditSnippets = $editSnippets;
                }
            }
        }

        parent::createAction();
    }
613657
public function createAction($storage)
    {
        $this->storageRepository->add($storage);
        $this->generateAction();
        $html = $this->htmlCodeGenerator->generateHtml($storage["elements"]["key"], 'tt_content');
        $this->saveHtml($storage["elements"]["key"], $html);
        $this->addFlashMessage(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_mask.content.newcontentelement',
            'mask'));
        $this->redirectByAction();
    }
809839
public function create($context = null)
    {
        try {
            $this->context = strlen($context) ? $context : $this->getConfig('create[context]', self::CONTEXT_CREATE);
            $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
                "{$this->context}[title]",
                'backend::lang.form.create_title'
            );

            $model = $this->controller->formCreateModelObject();
            $model = $this->controller->formExtendModel($model) ?: $model;

            $this->initForm($model);
        }
        catch (Exception $ex) {
            $this->controller->handleError($ex);
        }
    }
1253541
protected function CreateSubLevel(NavigationItem $parent)
    {
        $navigation = new self();
        $navigation->isSubLevel = true;
        $navigation->naviParent = $parent;
        $navigation->SetTreeItem($this->tree, $this->item);
        return $navigation;
    }
1095015
public function registerNavigation()
    {
        $configuration = $this->getConfigurationFromYaml();
        if (array_key_exists('navigation', $configuration)) {
            $navigation = $configuration['navigation'];

            if (is_array($navigation)) {
                array_walk_recursive($navigation, function (&$item, $key) {
                    if ($key === 'url') {
                        $item = Backend::url($item);
                    }
                });
            }

            return $navigation;
        }
    }
755666
public function generate($controller)
    {
        if (!$controller instanceof Controller) {
            $controller = new $controller('', null);
        }
        $this->controller = get_class($controller);
        $this->admin = $controller->admin;
        $this->title = $controller->name;
        $this->description = $controller->description;
    }
1005454
private function createBlockCreateForm(Block $entity)
    {

        $types = $this->container->getParameter('flowcode_page.block_types');
        $class = $types[$entity->getType()]["class_type"];

        $form = $this->createForm(new $class(), $entity, array(
            'action' => $this->generateUrl('admin_page_block_create', array("type" => $entity->getType())),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }
256987
public function publish(Navigation $navigation)
    {
        $navigation->togglePublishedState();

        return $this->notifySuccess(sprintf(
            trans('cms::navigation.update.publish'),
            $navigation->published ? 'published' : 'unpublished'
        ));
    }