/** * {@inheritdoc} */ public function getTitle(Request $request, Route $route) { $route_title = NULL; // A dynamic title takes priority. Route::getDefault() returns NULL if the // named default is not set. By testing the value directly, we also avoid // trying to use empty values. if ($callback = $route->getDefault('_title_callback')) { $callable = $this->controllerResolver->getControllerFromDefinition($callback); $arguments = $this->controllerResolver->getArguments($request, $callable); $route_title = call_user_func_array($callable, $arguments); } elseif ($title = $route->getDefault('_title')) { $options = array(); if ($context = $route->getDefault('_title_context')) { $options['context'] = $context; } $args = array(); if ($raw_parameters = $request->attributes->get('_raw_variables')) { foreach ($raw_parameters->all() as $key => $value) { $args['@' . $key] = $value; $args['%' . $key] = $value; } } if ($title_arguments = $route->getDefault('_title_arguments')) { $args = array_merge($args, (array) $title_arguments); } // Fall back to a static string from the route. $route_title = $this->t($title, $args, $options); } return $route_title; }
/** * Returns the result of invoking the sub-controller. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param mixed $controller_definition * A controller definition string, or a callable object/closure. * * @return mixed * The result of invoking the controller. Render arrays, strings, HtmlPage, * and HtmlFragment objects are possible. */ public function getContentResult(Request $request, $controller_definition) { if ($controller_definition instanceof \Closure) { $callable = $controller_definition; } else { $callable = $this->controllerResolver->getControllerFromDefinition($controller_definition); } $arguments = $this->controllerResolver->getArguments($request, $callable); $page_content = call_user_func_array($callable, $arguments); return $page_content; }
/** * {@inheritdoc} */ public function getTitle(LocalTaskInterface $local_task) { $controller = array($local_task, 'getTitle'); $request = $this->requestStack->getCurrentRequest(); $arguments = $this->controllerResolver->getArguments($request, $controller); return call_user_func_array($controller, $arguments); }
/** * Invokes the form and returns the result. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return array * The render array that results from invoking the controller. */ public function getContentResult(Request $request) { $form_object = $this->getFormObject($request, $this->formDefinition); // Add the form and form_state to trick the getArguments method of the // controller resolver. $form_state = array(); $request->attributes->set('form', array()); $request->attributes->set('form_state', $form_state); $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm')); $request->attributes->remove('form'); $request->attributes->remove('form_state'); // Remove $form and $form_state from the arguments, and re-index them. unset($args[0], $args[1]); $form_state['build_info']['args'] = array_values($args); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Invokes the form and returns the result. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return array * The render array that results from invoking the controller. */ public function getContentResult(Request $request, RouteMatchInterface $route_match) { $form_arg = $this->getFormArgument($route_match); $form_object = $this->getFormObject($route_match, $form_arg); // Add the form and form_state to trick the getArguments method of the // controller resolver. $form_state = new FormState(); $request->attributes->set('form', []); $request->attributes->set('form_state', $form_state); $args = $this->controllerResolver->getArguments($request, [$form_object, 'buildForm']); $request->attributes->remove('form'); $request->attributes->remove('form_state'); // Remove $form and $form_state from the arguments, and re-index them. unset($args[0], $args[1]); $form_state->addBuildInfo('args', array_values($args)); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Ensures bubbleable metadata from early rendering is not lost. * * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event * The controller event. */ public function onController(FilterControllerEvent $event) { $controller = $event->getController(); // See \Symfony\Component\HttpKernel\HttpKernel::handleRaw(). $arguments = $this->controllerResolver->getArguments($event->getRequest(), $controller); $event->setController(function () use($controller, $arguments) { return $this->wrapControllerExecutionInRenderContext($controller, $arguments); }); }