Generates a \Zend_Navigation object from the current menu

@param \Zend_Controller_Request_Abstract $request
@param mixed $actionController
@return \Zend_Navigation
355256
public function toZendNavigation(\Zend_Controller_Request_Abstract $request, $actionController = null)
    {
        if ($this->_onlyActiveBranchVisible) {
            $activePath = $this->_findPath($request);

            // \MUtil_Echo::r($activePath);
            $this->setBranchVisible($activePath);
        }

        $parameterSources = func_get_args();

        if ($this->_menuParameters) {
            $parameterSources[] = $this->_menuParameters;
        }

        $source = new \Gems_Menu_ParameterCollector($parameterSources);
        // self::$verbose = true;

        $nav = new \Zend_Navigation($this->_toNavigationArray($source));

        // \MUtil_Echo::track($this->_toNavigationArray($source), $nav);

        return $nav;
    }
135261
public function handleAction($request, $action)
    {
        $handles = parent::allowedActions(false);
        $defaultMapping = $this->stat('allowed_actions');
        $handles['index'] = 'handleIndex';
        $siteConfig = SiteConfig::current_site_config();
        foreach ($defaultMapping as $key) {
            $map = ucfirst($key . 'Action');
            if ($siteConfig->$map) {
                $handles[$siteConfig->$map] = $key;
            }
            if (!array_key_exists($key, $handles)) {
                $handles[$key] = $key;
            }
        }
        self::$url_handlers = $handles;
        $this->needsRedirect();

        return parent::handleAction($request, $handles[$action]);
    }
363623
public function ajaxControllerAction(Request $request)
    {
        $operation = $request->request->get('operation') ? $request->request->get('operation') : $request->query->get(
            'operation'
        );

        if (!$operation) {
            throw new NotFoundHttpException();
        }

        return new JsonResponse($this->$operation());
    }
432267
protected function _getUtilityNavigation()
    {
        $action = $this->_action();

        $utilityNavigation = $action->getConfig('scaffold.utility_navigation');
        if ($utilityNavigation === null) {
            $utilityNavigation = [
                new MenuItem('Account', ['controller' => 'Users', 'action' => 'account']),
                new MenuItem('Log Out', ['controller' => 'Users', 'action' => 'logout']),
            ];
        }

        return $utilityNavigation;
    }
472507
public function index(Request $request)
    {
        $menu = Menu::defaultOrder()->get()->toTree();

        return $this->response()->collection($menu, new MenuTransformer());
    }
1085684
public function getController(Request $request, array $matched)
    {
        if (null !== $request->attributes->get('_controller')) {
            return $this->createController($request->attributes->get('_controller'));
        }

        if ( ! $controller = $matched['_controller']) {
            throw new \InvalidArgumentException('Unable to look for controller as the "_controller" parameter is missing');
        }

        $callable = $this->createController($controller);

        if ( ! is_callable($callable)) {
            throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request));
        }

        return $callable;
    }
922532
public function getAfterLoginRedirectionUri(ActionRequest $actionRequest)
    {
        $user = $this->userService->getBackendUser();
        if ($user === null) {
            return null;
        }

        $workspaceName = $this->userService->getPersonalWorkspaceName();
        $this->createWorkspaceAndRootNodeIfNecessary($workspaceName);

        $uriBuilder = new UriBuilder();
        $uriBuilder->setRequest($actionRequest);
        $uriBuilder->setFormat('html');
        $uriBuilder->setCreateAbsoluteUri(true);

        $nodeToEdit = $this->getLastVisitedNode($workspaceName);
        if ($nodeToEdit === null) {
            $contentContext = $this->createContext($workspaceName);
            $nodeToEdit = $contentContext->getCurrentSiteNode();
        }

        $arguments = array_merge(['node' => $nodeToEdit], $this->routingValuesAfterLogin);
        return $uriBuilder->uriFor($this->routingValuesAfterLogin['@action'], $arguments, $this->routingValuesAfterLogin['@controller'], $this->routingValuesAfterLogin['@package']);
    }
746237
private static function render($actionContext) {
        $controller = $actionContext->getController();

        // annotation and validation
        $modelState = $actionContext->getModelState();
        self::annotateAndValidateModel($modelState);

        // filters
        $actionExecutingContext = self::actionExecutingFilters($actionContext);

        if (($actionResult = $actionExecutingContext->getResult()) === null) {
            try {
                // execute action
                $actionResult = self::executeAction($actionContext);
                // filters
                $actionExecutedContext = self::actionExecutedFilters($actionContext, $actionResult);
                // set result
                $actionResult = $actionExecutedContext->getResult();
            }
            catch (\Exception $ex) {
                // set status code
                $actionContext->getHttpContext()->getResponse()->setStatusCode(500);
                // add the error to the modelState
                $modelState->addError('.', $ex);
                // filters
                $exceptionContext = self::exceptionFilters($actionContext, $ex);
                if (($actionResult = $exceptionContext->getResult()) === null) {
                    if ($exceptionContext->getExceptionHandled()) {
                        // executed filters
                        $actionExecutedContext = self::actionExecutedFilters($actionContext, $actionResult, $exceptionContext);
                        // set result
                        $actionResult = $actionExecutedContext->getResult();
                    }
                    else {
                        $actionResult = new ExceptionResult($ex);
                    }
                }
            }
        }

        if (isset($actionResult)) {
            // transformation of known types
            if (is_callable($actionResult)) {
                $actionResult = $actionResult();
            }

            if (is_scalar($actionResult)) {
                $actionResult = new ContentResult($actionResult, 'text/plain');
            }
            if ((($resultType = gettype($actionResult)) === 'object' || $resultType === 'array') && !$actionResult instanceof ActionResult) {
                $actionResult = new JsonResult($actionResult);
            }

            // make result
            if ($actionResult instanceof ViewResult || $actionResult instanceof ExceptionResult) {
                // create view data
                $viewData = $modelState->getKeyValuePair();
                $controllerViewData = InternalHelper::getPropertyValueOfParentClass($controller, 'viewData');

                if (!empty($controllerViewData)) {
                    $viewData = array_unique(array_merge($viewData, $controllerViewData), \SORT_STRING);
                }

                // create view
                $viewContext = InternalHelper::makeViewContext(
                    (!empty($actionResult->viewFile) ? $actionResult->viewFile : PHPMVC_CURRENT_VIEW_PATH),
                    $actionContext,
                    $actionResult,
                    null,
                    $viewData,
                    null,
                    null,
                    null
                );

                // get content
                $result = InternalHelper::getTopLevelViewContext($viewContext)->content;

                // render
                $response = $actionContext->getHttpContext()->getResponse();
                $response->write($result);
                $response->end();
            }
            elseif ($actionResult instanceof ActionResult) {
                // execute result with action context
                $actionResult->execute($actionContext);
            }
        }
    }
1123415
protected function forwardToRequest(ActionRequest $request)
    {
        $packageKey = $request->getControllerPackageKey();
        $subpackageKey = $request->getControllerSubpackageKey();
        if ($subpackageKey !== null) {
            $packageKey .= '\\' . $subpackageKey;
        }
        $this->forward($request->getControllerActionName(), $request->getControllerName(), $packageKey, $request->getArguments());
    }
74956
public function update($menu = null, $model, FormRequest $request)
    {
        $data = $request->all();
        $data['parent_id'] = $data['parent_id'] ?: null;
        $data['page_id'] = $data['page_id'] ?: null;
        $this->repository->update($data);

        return $this->redirect($request, $model);
    }
1021326
public function indexAction(Request $request)
    {
        // Make sure we have a menu for each possible locale
        $this->container->get('kunstmaan_menu.menu.service')->makeSureMenusExist();

        return parent::doIndexAction(
            $this->getAdminListConfigurator($request),
            $request
        );
    }
1020300
public function resolve(Request $request)
    {
        $attributes = $this->urlMatcher->match($request->getPathInfo());
        $controllerNotation = explode('@', $attributes['_route']);
        unset($attributes['_route']);

        $controller = explode(':', $controllerNotation[0]);

        $total = count($controller);
        $last = $total - 1;

        $controller[$total] = sprintf('%sController', $controller[$last]);
        $controller[$last] = 'Controller';

        $action = sprintf('%sAction', $controllerNotation[1]);
        unset($controllerNotation);

        $class = implode('\\', $controller);
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class "%s" is not exist.', $class));
        }

        $implements = class_implements($class);
        if (!array_key_exists(ControllerInterface::class, $implements)) {
            throw new \InvalidArgumentException(sprintf('"%s" must implement "%s"', $class, ControllerInterface::class));
        }

        return array(
            '_controller' => $class,
            '_action' => $action,
            '_parameters' => $attributes,
        );
    }
282670
protected function callController($callable, Request $request)
    {
        list($class, $action) = explode('@', $callable[0], 2);

        // Make sure any route parts are available as query parameters from the request.
        $request->query->add($callable[1]);

        $controller = $this->factory->make($class);
        $controller->setRequest($request);

        return $controller->call($action);
    }
463026
public function render(\Zend_View_Abstract $view)
    {
        $request = $this->_getOriginalRequest();

        if ($this->_onlyActiveBranchVisible) {
            $activePath = $this->_findPath($request);

            // \MUtil_Echo::r($activePath);

            $this->setBranchVisible($activePath);
        }

        $parameterSources[] = $request;

        if ($this->_menuParameters) {
            $parameterSources[] = $this->_menuParameters;
        }

        $source = new \Gems_Menu_ParameterCollector($parameterSources);
        // self::$verbose = true;

        $nav = $this->_toNavigationArray($source);

        // \MUtil_Echo::track($nav);

        $ul = $this->renderFirst();

        $this->renderItems($ul, $nav, true);

        return $ul->render($view);
    }
35036
public function createPlacementNavigation($rootNode, $admin, $controller, $menuItemManager)
    {
        $lastEdited = $this->get('session')->get('MenuItem.last_edited');

        $nodeDecorator = function ($node) use ($admin, $controller, $menuItemManager, $lastEdited) {
            if ($lastEdited == $node['id']) {
                return;
            }
            $node = $menuItemManager->find($node['id']);

            return $controller->renderView(
                '@NetworkingInitCms/MenuItemAdmin/placement_item.html.twig',
                ['admin' => $admin, 'last_edited' => $lastEdited, 'node' => $node]
            );
        };

        $childOpen = function ($node) use ($lastEdited) {
            if ($lastEdited == $node['id']) {
                return;
            }

            return sprintf(
                '<li class="table-row-style list_item" id="listItem_%s">',
                $node['id']
            );
        };

        $childClose = function ($node) use ($lastEdited, $admin, $controller) {
            if ($lastEdited == $node['id']) {
                return;
            }

            return $controller->renderView(
                '@NetworkingInitCms/MenuItemAdmin/placement_item_end.html.twig',
                ['admin' => $admin, 'last_edited' => $lastEdited, 'node' => $node]
            );
        };

        $rootOpen = function ($tree) {
            $node = $tree[0];
            if ($node['lvl'] == 1) {
                $class = 'ui-sortable';
            } else {
                $class = 'table-row-style';
            }

            return sprintf('<ul class="%s">', $class);
        };

        $navigation = $menuItemManager->childrenHierarchy(
            $rootNode,
            null,
            [
                'rootOpen' => $rootOpen,
                'decorate' => true,
                'childOpen' => $childOpen,
                'childClose' => $childClose,
                'nodeDecorator' => $nodeDecorator,
            ],
            false
        );

        return $navigation;
    }
731131
public function menuAction()
    {
        $params     = $this->params();
        $navigation = $this->getServiceLocator()
                           ->get( 'Grid\Menu\Model\Menu\Model' )
                           ->findNavigation( $params->fromRoute( 'id' ) );

        $view = new ViewModel( array(
            'navigation' => $navigation,
        ) );

        $this->getResponse()
             ->getHeaders()
             ->addHeaderLine( 'Content-Type', 'application/xml' );

        return $view->setTerminal( true );
    }
833222
public function newAction(Request $request)
    {
        $menu = new MenuItem();
        $form = $this->createForm('CoreExtraBundle\Form\MenuItemType', $menu, array('uploadDir'=> 'uploads/images/menu'));
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            
            //clean image form
            $this->get('core_manager')->cleanImageForm($request->files->get('menu_item'), $menu);
            
            $em = $this->getDoctrine()->getManager();
            $em->persist($menu);
            $em->flush();
            
            //images
            $image = $form->getNormData()->getImage();
            if ($image instanceof Image) {
                $this->get('core_manager')->uploadMenuImage($menu);
            }
            
            $this->get('session')->getFlashBag()->add('success', 'menu.created');

            return $this->redirectToRoute('coreextra_menuitem_show', array('id' => $menu->getId()));
        }

        return array(
            'entity' => $menu,
            'form' => $form->createView(),
        );
    }