Create primary menu (if it doesn't exist.

@return bool
505733
public static function createPrimaryMenu()
    {
        $check = Menu::where('slug', 'primary')->get()->first();
        if(!$check) {

            $create = factory(Menu::class)->create(
                [
                'title' => 'Primary',
                'slug' => 'primary',
                'isPrimary' => true,
                ]
            );

            if($create) {
                return true;
            }
        }
        return false;
    }
771105
public static function create() 
    {
		$alias = func_get_arg(0);
		$name = func_get_arg(1);
		
        try {
            $m = self::getByAlias($alias);
        } catch (\Exception $e) {}
        
        if ($m) throw new Exception\CMS('Меню c таким алиасом уже существует.');
        
        self::getDbConnection()->insert('menus', array(
			'alias' => $alias,
			'name'  => $name
		));
  		return self::getById( self::getDbConnection()->lastInsertId() );
  	}
1357617
public function secondaryMenuActions()
    {
        if ($this->secondaryMenuActions === null) {
            $ident    = $this->ident();
            $metadata = $this->adminSecondaryMenu();
            if (isset($metadata[$ident]['actions'])) {
                $actions = $metadata[$ident]['actions'];
            } else {
                $actions = [];
            }
            $this->setSecondaryMenuActions($actions);
        }

        if ($this->parsedSecondaryMenuActions === false) {
            $this->parsedSecondaryMenuActions = true;
            $this->secondaryMenuActions = $this->createSecondaryMenuActions($this->secondaryMenuActions);
        }

        return $this->secondaryMenuActions;
    }
75538
public function makeSureMenusExist()
    {
        $locales = array_unique($this->getLocales());
        $required = array();

        foreach ($this->menuNames as $name) {
            $required[$name] = $locales;
        }

        $menuObjects = $this->em->getRepository($this->menuEntityClass)->findAll();

        foreach ($menuObjects as $menu) {
            if (array_key_exists($menu->getName(), $required)) {
                $index = array_search($menu->getLocale(), $required[$menu->getName()]);
                if ($index !== false) {
                    unset($required[$menu->getName()][$index]);
                }
            }
        }

        foreach ($required as $name => $locales) {
            foreach ($locales as $locale) {
                $className = $this->menuEntityClass;
                $menu = new $className();
                $menu->setName($name);
                $menu->setLocale($locale);
                $this->em->persist($menu);
            }
        }

        $this->em->flush();
    }
321276
public function isCreate()
    {
        $primary = $this->primaryKey();
        foreach ($primary as $column) {
            if (!empty($this->_context['defaults'][$column])) {
                return false;
            }
        }

        return true;
    }
1299769
protected function createMenu()
    {
        $handler = $this->handler->add($this->getAttribute('id'), $this->getAttribute('position'));

        if (!is_null($handler)) {
            $handler->title($this->getAttribute('title'))
                    ->link($this->getAttribute('link'))
                    ->icon($this->getAttribute('icon'))
                    ->entity($this->getAttribute('entity'))
                    ->active($this->getAttribute('active'));
            if (!is_null($type = $this->getAttribute('type'))) {
                $handler->type($type);
            }
            return $handler;
        }
        return false;
    }
267457
public function create()
    {
        $roles = Role::getAllLists();
        $parents = NavigationAdmin::getAllLists();

        return $this->view('titan::settings.navigation.add_edit')
            ->with('roles', $roles)
            ->with('parents', $parents);
    }
368426
public function menu($menu = null, $options = array())
	{
		$menu = $menu ?: $this->getDefaultMenu();

		// If the given menu has not been created before, we will create the instances
		// here and cache it so we can return it next time very quickly. If there is
		// already a menu created by this name, we'll just return that instance.
		if (!isset($this->menus[$menu]))
		{
			$this->menus[$menu] = $this->createMenu($menu, $options);
		}

		return $this->menus[$menu];
	}
104112
public function createCustom()
    {
        $parentsSelect = Menu::where('menu_type', 2)->pluck('title', 'id')->prepend('-- no parent --', '');
        $roles         = Role::all();

        return view('qa::menus.createCustom', compact('parentsSelect', 'roles'));
    }
221066
public function sideMenu()
    {
        $menu = $this->factory->createItem('root');

        $this->dispatcher->dispatch(
            ConfigureMenuEvent::CONFIGURE,
            new ConfigureMenuEvent($this->factory, $menu)
        );

        return $menu;
    }
1162157
protected function initializeMenus()
    {
        foreach ($this->config('menu') as $name => $config) {
            Menu::create($name, $config);
        }

        // Add default menu items to sidebar
        if ($appshellMenu = Menu::get('appshell')) {
            // CRM Group
            $crm = $appshellMenu->addItem('crm_group', __('CRM'));

            $crm
                ->addSubItem('customers', __('Customers'), ['route' => 'appshell.customer.index'])
                ->data('icon', 'accounts-list')
                ->allowIfUserCan('list customers');

            // Settings Group
            $settings = $appshellMenu->addItem('settings_group', __('Settings'));

            $settings
                ->addSubItem('users', __('Users'), ['route' => 'appshell.user.index'])
                ->data('icon', 'accounts')
                ->allowIfUserCan('list users');
            $settings
                ->addSubItem('roles', __('Permissions'), ['route' => 'appshell.role.index'])
                ->data('icon', 'shield-security')
                ->allowIfUserCan('list roles');
            $settings
                ->addSubItem('settings', __('Settings'), ['route' => 'appshell.settings.index'])
                ->data('icon', 'settings')
                ->allowIfUserCan('list settings');
        }
    }
982626
private function find_main_submenu() {
			global $submenu;

			$top_level_menu_slug = $this->get_top_level_menu_slug();

			if ( ! isset( $submenu[ $top_level_menu_slug ] ) ) {
				return false;
			}

			$submenu_slug = $this->get_raw_slug();

			$position   = - 1;
			$found_submenu = false;

			$hook_name = get_plugin_page_hookname( $submenu_slug, '' );

			foreach ( $submenu[ $top_level_menu_slug ] as $pos => $sub ) {
				if ( $submenu_slug === $sub[2] ) {
					$position   = $pos;
					$found_submenu = $sub;
				}
			}

			if ( false === $found_submenu ) {
				return false;
			}

			return array(
				'menu'        => $found_submenu,
				'parent_slug' => $top_level_menu_slug,
				'position'    => $position,
				'hook_name'   => $hook_name
			);
		}
42634
protected function makeSidebar()
    {
        $this->navigation->create(Navigable::MENU_SIDEBAR, function (MenuBuilder $sidebar) {
            $sidebar->header('Main Menu');

            // Dashboard
            $sidebar->route('scaffold.dashboard', trans('administrator::module.dashboard'), [], 1, [
                'id' => 'dashboard',
                'icon' => 'fa fa-dashboard',
                'active' => str_is(request()->route()->getName(), 'scaffold.dashboard'),
            ]);

            // Create new users group
            $sidebar->dropdown(trans('administrator::module.groups.users'), function (MenuItem $sub) {
                $sub->route('scaffold.create', trans('administrator::buttons.create_item', ['resource' => 'User']), ['module' => 'users'], 1, []);
            }, 2, ['id' => 'groups', 'icon' => 'fa fa-group']);
        });
    }
788524
public function bootMenus()
    {
        $name = 'menu.top.right';
        view()->composer('antares/foundation::*', function () use ($name) {
            if (!Registry::isRegistered('menu.' . $name)) {
                $this->app->instance($name, $this->app->make('antares.widget')->make($name));
                $selector = new ComponentsSelector($this->app, $name);
                $selector->handle();
                Registry::set('menu.' . $name, $selector);
            }
        });
    }
1284667
public function actionCreate()
    {
        $this->layout = static::FORM_LAYOUT;
        $model = new $this->MainModel;

        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if(empty($model->Menu_id)) {
                Yii::info('Making the new node as root');
                $model->makeRoot();
            } else {
                $parent_node = Menu::findOne($model->Menu_id);
                $model->appendTo($parent_node);

                Yii::info('Making the new node as a child of ' . $parent_node->id);
            }
            $this->saveHistory($model, $this->historyField);
            return $this->redirect(['index']);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
822153
public function createOptions()
    {
        // default options
        $options = [
            'public' => true,
            'rewrite' => [
                'slug' => $this->slug
            ]
        ];

        // replace defaults with the options passed
        $options = array_replace_recursive($options, $this->options);

        // create and set labels
        if (!isset($options['labels'])) {
            $options['labels'] = $this->createLabels();
        }

        // set the menu icon
        if (!isset($options['menu_icon']) && isset($this->icon)) {
            $options['menu_icon'] = $this->icon;
        }

        return $options;
    }
303253
public function getMainItem()
    {
        $menuPage = $this->menuBuilder->getTopNavbar()->getChild('menu.page');

        if ($menuPage) {
            return $menuPage;
        } else {
            return $this->menuBuilder->createDropdownMenuItem(
                $this->menuBuilder->getTopNavbar(),
                'menu.page'
            );
        }
    }