Create element

@param type $menuItems
@return type
975263
public function render(DOMNode $Node, $menuItems, $menuType = "nav", $menuDepth = 3, $menuIcons = true, array $parents = [])
    {

        $list = $Node->ownerDocument->createElement("ul");
        $depth = 1;

        //$hasActive  = false;
        foreach ($menuItems as $item) {

            //if this user does not have access to this menu ignore it
            if (!empty($item['menu_url'])):
                //check has permission;
                $menuItemRenderEvent = new Event('Layout.beforeRender.menu.item', $this, ["item" => $item]);

                //Callbacks on each Node;
                $this->observer->trigger($menuItemRenderEvent); //Parse the Node;


                $item = $menuItemRenderEvent->getResult();


                if (!isset($item['menu_viewable']) || !$item['menu_viewable']) {
                    continue;
                }

            endif;

            //@TODO Menu Plugins
            //Search for all plugin placemarkers in menu item names
            //Search for (?<=\$\{)([a-zA-Z]+)(?=\}) and replace with data
//            if (preg_match_all('/(?:(?<=\%\{)).*?(?=\})/i', $item['menu_title'], $matches)) {
//                $placemarkers = (is_array($matches) && isset($matches[0])) ? $matches[0] : array();
//                foreach ($placemarkers as $k => $dataid) {
//                    //@TODO Now call all menu items plugins
//                    $item['menu_title'] = $dataid;
//                }
//                //Replace with data;
//                continue;
//            }

            //@TODO check if this is the current menu item and set it as active
            //Checked in the helper and rendered at $item["menu_isactive"];
            $active = (isset($item["menu_isactive"]) && (bool)$item["menu_isactive"]) ? true : false;
            $class = str_replace(array(" ", "(", ")", "-", "&", "%", ",", "#"), '-', strtolower($item['menu_title']));

            //Add the active class to the parent;
            if ($active && !empty($parents)) {
                foreach ($parents as $parent) {
                    if (is_a($parent, DOMNode::class)) {
                        if ($parent->hasAttribute("class")) {
                            if (preg_match("/\bactive\b/i", $parent->getAttribute("class"))) {
                                continue;
                            }
                            $parent->setAttribute("class", "active " . $parent->getAttribute("class"));
                        }
                        $parent->setAttribute("class", "active");
                    }
                }
            }


            //Create a link element;
            $link = $Node->ownerDocument->createElement("li");
            $link->setAttribute("class", 'link-' . $class . " " . ((isset($item['menu_classes']) && !empty($item['menu_classes'])) ? $item['menu_classes'] : "") . (($active) ? " active " : ""));


            //Create the anchor and add to the link
            $anchor = $Node->ownerDocument->createElement("a");
            $anchor->setAttribute("href", $item["menu_url"]);
            $anchor->setAttribute("title", $item["menu_title"]);

            //Show menu Icons?
            if ($menuIcons) {
                //If we have a menu count
                $icon = $Node->ownerDocument->createElement("i");
                $icon->setAttribute("class", "menu-icon icon-{$class}");

                $anchor->appendChild($icon);

            }

            //create the anchor title;
            $title = $Node->ownerDocument->createElement("span");
            $title->setAttribute("class", "menu-text");
            $title->setAttribute("title", $item["menu_title"]);
            $title->appendChild($Node->ownerDocument->createTextNode($item["menu_title"]));

            //Append the title to the anchor
            $anchor->appendChild($title);


            //Show an unread count?
            if (isset($item['menu_count'])) {

                //If we have a menu count
                $important = (isset($item['menu_count_unimportant']) && (bool)$item['menu_count_unimportant'] || (int)$item['menu_count'] < 1) ? null : "label-important";

                $badge = $Node->ownerDocument->createElement("span");
                $badge->setAttribute("class", "badge " . ((!$menuIcons) ? " absolute-right" : "nav-icon-label") . " {$important}");
                $badge->appendChild($Node->ownerDocument->createTextNode(number_format($item['menu_count'])));


                $anchor->appendChild($badge);
            }


            //Count children
            if (isset($item['children']) && count($item['children']) > 0 && $depth < $menuDepth) {

                //Dropdown li

                $caret = $Node->ownerDocument->createElement("b");
                $caret->setAttribute("class", "caret");
                $anchor->appendChild($caret);

                //Add the menu anchor
                $link->appendChild($anchor);

                //$link->setAttribute("class",  'dropdown ' . $link->getAttribute("class"));

                $parents[] = $link;

                $_list = $this->render($Node, (array)$item['children'], $menuType, $menuDepth, $menuIcons, $parents);


                $parents = [];

                //Dropdown ul
                $_list->setAttribute("class", 'nav menu ' . $_list->getAttribute("class"));

                $link->appendChild($_list);
                $depth++;

            } else {
                //Just Add the menu anchor
                $link->appendChild($anchor);
            }
            $list->appendChild($link);
        }

        $list->setAttribute("class", $menuType);

        return $list;
    }
554324
public function editMenuItemLabelAction(MenuItemLabel $menuItemlabel)
    {
        $em = $this->getDoctrine()->getManager();

        if (!$menuItemlabel) {
            throw $this->createNotFoundException('Unable to find MenuItem entity.');
        }
        $editForm = $this->createForm($this->get("amulen.page.form.menuitemlabel"), $menuItemlabel, array(
            'action' => $this->generateUrl('admin_menu_item_label_update', array('id' => $menuItemlabel->getId())),
            'method' => 'PUT',
        ));
        $editForm->add('submit', 'submit', array('label' => 'Update'));

        return array(
            'entity' => $menuItemlabel,
            'form' => $editForm->createView(),
        );
    }
1363666
public function add(MenuItem $item)
    {
        $this->collection[$this->count] = $item;
        $this->names[$item->getName()]  = $this->count;

        $this->count++;

        return $this;
    }
846115
public function createProductionMenu(array $options): ItemInterface
    {
        $menu = $this->factory->createItem('root');

        // No group context means return empty menu.
        if (null === $group = $this->group_context->getContext()) {
            return $menu;
        }

        $menu->setLabel($group->getName());
        $menu->setExtra('translation_domain', false);

        // Dispatch event to populate the menu.
        $event = new ProductionMenuCollectionEvent($menu, $group);
        $this->dispatcher->dispatch(ProductionMenuCollectionEvent::NAME, $event);

        return $menu;
    }
597969
public function setItem(\Wucdbm\Bundle\MenuBuilderBundle\Entity\MenuItem $item) {
        $this->item = $item;

        return $this;
    }
233958
public static function create($elements) {
    /** @var ArrayNode $node */
    $node = Parser::parseExpression('[]');
    /** @var \Pharborist\Node $element */
    foreach ($elements as $element) {
      $node->getElementList()->appendItem($element);
    }
    return $node;
  }
11287
public function &addItem(MenuItem $menu_item)
    {
        $this->items[$menu_item->getName()] = $menu_item;

        return $this->items[$menu_item->getName()];
    }
906213
public function create($name){
        $this->menuCollection[$name] = new MenuCollection;
        $this->menuCollection[$name]->setName($name);

        return $this->menuCollection[$name];
    }
173709
private function createCreateForm(Menu $entity)
    {
        $form = $this->createForm(new MenuType(), $entity, array(
            'action' => $this->generateUrl('admin_menu_create'),
            'method' => 'POST',
        ));

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

        return $form;
    }
1067136
public function subMenu($key = null, $menuItem = null)
    {
        if (null === $menuItem) {
            return $this->subMenu;
        }

        if (is_callable($menuItem)) {
            $menu = new AdminMenu($menuItem);
            $this->subMenu[$key] = $menu;
        } else {
            $this->subMenu[$key] = $menuItem;
        }

        return $this;
    }
1357954
public function addItem($menuId, $parentId = null)
    {
        if (!$menuId || !$this->Menus->exists(['id' => $menuId])) {
            throw new NotFoundException();
        }

        if ($parentId !== null && !$this->MenuItems->exists(['id' => $parentId])) {
            $this->Flash->error(__d('wasabi_core', 'A menu item with id <strong>{0}</strong> does not exist.', $parentId));
            $this->redirect(['action' => 'edit', $menuId]);
            return;
        }

        if (!$this->request->is(['get', 'post'])) {
            throw new MethodNotAllowedException();
        }

        $menuItem = $this->MenuItems->newEntity();
        if ($this->request->is('post') && !empty($this->request->data)) {
            $menuItem = $this->MenuItems->patchEntity($menuItem, Hash::merge($this->request->data, [
                'menu_id' => $menuId,
                'parent_id' => $parentId
            ]));
            $this->MenuItems->setScope($menuId);
            if ($this->MenuItems->save($menuItem)) {
                $this->Flash->success(__d('wasabi_core', 'Menu Item <strong>{0}</strong> has been created.', [$this->request->data['name']]));
                $this->redirect(['action' => 'edit', $menuId]);
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }
        $this->set([
            'menu' => $this->Menus->get($menuId),
            'menuItem' => $menuItem,
            'linkTypes' => $this->Menus->getLinkTypes()
        ]);
    }
12462
protected function createElement(array $params = [])
    {
        $root = $this->createRoot();
        foreach ($params as $param) {
            $this->addElement($param, $root);
        }

        return $root;
    }
704520
public function addChild(\Amulen\PageBundle\Entity\MenuItem $children)
    {
        $this->children[] = $children;

        return $this;
    }
593151
public function createStructure(array $options): ItemInterface
    {
        /** @var bool $location */
        $canDelete = $this->permissionResolver->hasAccess('content', 'cleantrash');
        /** @var int $trashItemsCount */
        $trashItemsCount = $this->trashService->findTrashItems(new Query())->count;
        /** @var ItemInterface|ItemInterface[] $menu */
        $menu = $this->factory->createItem('root');

        $menu->addChild(
            $this->createMenuItem(self::ITEM__EMPTY, [
                'extras' => ['icon' => 'trash-empty'],
                'attributes' => $canDelete > 0 && $trashItemsCount > 0
                    ? ['data-toggle' => 'modal', 'data-target' => '#confirmEmptyTrash']
                    : ['class' => 'disabled'],
            ])
        );

        return $menu;
    }
1203011
public function newMenuItemAction(Menu $menu)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = new MenuItem();
        $entity->setMenu($menu);
        $form = $this->createMenuItemCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
266612
protected function add(array $properties = []): MenuItem
    {
        $properties['attributes']['id'] = $properties['attributes']['id'] ?? md5(json_encode($properties));
        $this->items->push($item = new MenuItem($properties));

        return $item;
    }
918118
public function create(Menu $menu)
    {
        $model = $this->repository->createModel();

        return view('menus::admin.create-menulink')
            ->with(compact('model', 'menu'));
    }