Show the form for creating a new resource.

@param  $menu

@return void
558095
public function create($menu = null)
    {
        $model = $this->repository->getModel();

        return view('menulinks::admin.create')
            ->with(compact('model', 'menu'));
    }
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(),
        );
    }
1234038
public function edit(string $id = null): void
    {
        $menuItem = $this->MenuItems->get($id, [
            'contain' => ['Menus']
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $data = (array)$this->request->getData();
            $menuItem = $this->MenuItems->patchEntity($menuItem, $data);
            if ($this->MenuItems->save($menuItem)) {
                $this->Flash->success((string)__('The menu item has been saved.'));
                $this->redirect(['controller' => 'Menus', 'action' => 'view', $menuItem->get('menu')->get('id')]);

                return;
            } else {
                $this->Flash->error((string)__('The menu item could not be saved. Please, try again.'));
            }
        }

        $parentMenuItems = $this->MenuItems
            ->find('treeList', ['spacer' => self::TREE_SPACER])
            ->where(['MenuItems.menu_id' => $menuItem->get('menu')->get('id'), 'MenuItems.id !=' => $id]);

        $this->set(compact('menuItem', 'parentMenuItems'));
        $this->set('_serialize', ['menuItem']);
    }
155404
public function add(): void
    {
        $menu = $this->Menus->newEntity();
        if ($this->request->is('post')) {
            $data = (array)$this->request->getData();
            $menu = $this->Menus->patchEntity($menu, $data);
            if ($this->Menus->save($menu)) {
                $this->Flash->success((string)__('The menu has been saved.'));
                $this->redirect(['action' => 'index']);

                return;
            } else {
                $this->Flash->error((string)__('The menu could not be saved. Please, try again.'));
            }
        }
        $this->set('navMenu', $menu);
        $this->set('_serialize', ['navMenu']);
    }
268260
protected function makeMenu($menu)
    {
        $links = [];
        foreach ($menu as $key => $item) {
            // Rebuild from associative array
            if (is_string($item)) {
                $item = [$key, $item];
            }

            list($endpoint, $label) = $item;
            $attributes = array_get($item, 4, []);

            // Compute actual URL
            $parameters = array_get($item, 2, []);
            $link = $this->router->getRoutes()->getByName($endpoint)
                ? $this->url->route($endpoint, $parameters)
                : $this->url->to($endpoint, $parameters);

            // Compute active state
            if ($link !== '#') {
                $active = array_get($item, 3) ?: str_replace($this->request->root().'/', null, $link);
                $active = $this->isOnPage($active);
            } else {
                $active = false;
            }

            $links[] = array_merge([
                'endpoint' => $link,
                'label' => $this->translate($label),
                'active' => $active ? 'active' : false,
            ], $attributes);
        }

        return $links;
    }
655913
public function onCreate(CreateResourceEvent $event)
    {
        $request = $this->container->get('request');
        $form = $this->formFactory->create(new DirectoryType(), new Directory());
        $form->handleRequest($request);

        if ($form->isValid()) {
            $published = $form->get('published')->getData();
            $event->setPublished($published);
            $event->setResources(array($form->getData()));
            $event->stopPropagation();

            return;
        }

        $content = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'directory'
            )
        );
        $event->setErrorFormContent($content);
        $event->stopPropagation();
    }
866269
private function createDir($path): void
    {
        if (! is_dir($path)) {
            mkdir($path, 0777, true);
            $this->info($path.' Has been created.');
        } else {
            $this->info($path.' Already created.');
        }
    }
1260939
public function actionAdd ()
		{

			$menu = new Menu();
			$this->_tpl = '@menuViews/add';
			$this->setTitle(Yii::tr('Add menu item', [], 'menu'));
			$type = MenuType::findOne(Yii::$app->request->get('type'));
			if ($type == null)
				return;
			$root = null;
			$parentId = Yii::$app->request->get('parentID');
			if (!is_null($parentId))
			{
				$root = Menu::findOne([ 'id' => $parentId, 'typeID' => $type->id ]);
				$this->setTitle(Yii::tr('Add menu subitem to {title}', [ 'title' => $root->title ], 'menu'));
			}

			if (Yii::$app->request->isPost)
			{
				$post = Yii::$app->request->post('Menu');

				if (is_null($root))
				{
					$root = Menu::findOne([ 'title' => $type->guid . '_ROOT', 'typeID' => $type->id ]);
					if ($root == null)
					{
						$root = new Menu([ 'title' => $type->guid . '_ROOT', 'typeID' => $type->id ]);
						$root->makeRoot();
					}
				}

				$menu->setAttributes([
					'title'  => $post[ 'title' ],
					'url'    => $post[ 'url' ],
					'path'   => $post[ 'path' ],
					'typeID' => $type->id
				]);

				$menu->appendTo($root);
				Yii::$app->notification->messageToSession(Yii::tr('Menu item was saved.', [], 'menu'));
				$this->redirect(Url::toRoute([ '/menu/index', 'type' => $type->id ]));
			}
			$this->data('model', $menu);
		}
218750
public function init()
    {
        $pages = $this->getModel()->getPages();

        // Check datas
        if (empty($pages)) {
            return;
        }

        global $admin_page_hooks;

        // Set the internal pointer of an array to its first element
        reset($pages);

        // Update identifier
        $identifier = Helpers::urlize(key($pages));
        $this->getModel()->setIdentifier($identifier);

        // Add root single menu if identifier is unknown
        if (!isset($admin_page_hooks[$identifier])) {
            $this->addRootPage();
        }

        // Iterate on pages
        foreach ($pages as $slug => $options) {
            if (empty($options)) {
                continue;
            }

            // Get slug
            $slug = Helpers::urlize($slug);

            // Add child menu
            $this->addChild($slug, $options);
        }
    }
277842
public function createMenuItemAction(Request $request, Menu $menu)
    {
        $entity = new MenuItem();
        $entity->setMenu($menu);
        $form = $this->createMenuItemCreateForm($entity);
        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            if($entity->getPage()){
                $entity->setPageSlug($entity->getPage());
            }

            $em->persist($entity);

            $this->get('amulen.page.service.menu')->reorder($menu);
            $em->flush();

            $availableLangs = $this->container->getParameter('flowcode_page.available_languages');
            foreach ($availableLangs as $key => $value) {
                $menuItemLabel = new MenuItemLabel();
                $menuItemLabel->setLang($key);
                $menuItemLabel->setContent($entity->getName());
                $menuItemLabel->setMenuItem($entity);
                $em->persist($menuItemLabel);
            }
            $em->flush();

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

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
1109168
public function showAction()
    {
        $this->setPageTitle(sprintf($this->_('Show %s'), $this->getTopic()));

        $model    = $this->getModel();
        // NEAR FUTURE:
        // $this->addSnippet('ModelVerticalTableSnippet', 'model', $model, 'class', 'displayer');
        $repeater = $model->loadRepeatable();
        $table    = $this->getShowTable();
        $table->setOnEmpty(sprintf($this->_('Unknown %s.'), $this->getTopic(1)));
        $table->setRepeater($repeater);
        $table->tfrow($this->createMenuLinks($this->menuShowIncludeLevel), array('class' => 'centerAlign'));

        if ($menuItem = $this->findAllowedMenuItem('edit')) {
            $table->tbody()->onclick = array('location.href=\'', $menuItem->toHRefAttribute($this->getRequest()), '\';');
        }

        $tableContainer = \MUtil_Html::create('div', array('class' => 'table-container'), $table);
        $this->html[] = $tableContainer;
    }
361407
public function toggleAction($id)
    {
        /** @var Menus_Entity_Table_Menu $table */
        $table = ORM::getTable($this->plugin, 'Menu');
        /** @var Menus_Entity_Menu $menu */
        $menu = $table->find($id);

        if (!is_null($menu))
        {
            $menu->active = !$menu->active;
            $table->update($menu);
        }

        HTTP::redirect(str_replace('&amp;', '&', $this->ui->url()));
    }
777782
public function edit($id)
    {
        $this->loadModel('Menu.Menus');
        $menu = $this->Menus->get($id);

        if ($this->request->data()) {
            $menu = $this->Menus->patchEntity($menu, $this->request->data(), [
                'fieldList' => [
                    'title',
                    'description',
                    'settings',
                ],
                'validate' => false
            ]);

            if ($this->Menus->save($menu, ['atomic' => true])) {
                $this->Flash->success(__d('menu', 'Menu has been saved!'));
                $this->redirect($this->referer());
            } else {
                $this->Flash->danger(__d('menu', 'Menu could not be saved, please check your information'));
            }
        }

        $this->title(__d('menu', 'Editing Menu'));
        $this->set('menu', $menu);
        $this->Breadcrumb
            ->push('/admin/menu/manage')
            ->push(__d('menu', 'Editing menu {0}', $menu->title), '#');
    }
1262003
public function form( $instance ) {
		parent::form( $instance );

		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );

		$selected_menu = isset( $instance['menu'] ) ? $instance['menu'] : '';

		$menu_field_name = $this->get_menu_field_id();

		?>

		<p>

			<label for="<?php echo esc_attr( $menu_field_name ) ?>">Menu:</label>

			<select id="<?php echo esc_attr( $menu_field_name ) ?>"
					name="<?php echo esc_attr( $menu_field_name ) ?>">

				<?php foreach ( $menus as $menu ) : ?>

					<option value="<?php echo esc_attr( $menu->slug ) ?>"
						<?php selected( $selected_menu, $menu->slug ); ?> >
						<?php echo esc_html( $menu->name ) ?>
					</option>

				<?php endforeach ?>

			</select>

		</p>

		<?php
	}
539250
public void create(Menu menu) {
        String url = WxEndpoint.get("url.menu.create");
        String json = JsonMapper.nonEmptyMapper().toJson(menu);
        logger.debug("create menu: {}", json);
        wxClient.post(url, json);
    }
680814
public function delete($id)
    {
        $this->loadModel('Menu.Menus');
        $menu = $this->Menus->get($id);

        if ($menu->handler === 'Menu' && $this->Menus->delete($menu)) {
            $this->Flash->success(__d('menu', 'Menu has been successfully deleted!'));
        } else {
            $this->Flash->danger(__d('menu', 'Menu could not be deleted, please try again'));
        }

        $this->title(__d('menu', 'Delete Menu'));
        $this->redirect($this->referer());
    }
1139900
public function onCreate(CreateResourceEvent $event)
    {
        $request = $this->container->get('request');
        $form = $this->container->get('form.factory')->create(new FileType(true), new File());
        $form->handleRequest($request);

        if ($form->isValid()) {
            $this->handleFileCreation($form, $event);
        }

        $content = $this->container->get('templating')->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => $event->getResourceType()
            )
        );
        $event->setErrorFormContent($content);
        $event->stopPropagation();
    }