ViewsMegarowController.php in Views Megarow 8
Namespace
Drupal\views_megarow\ControllerFile
src/Controller/ViewsMegarowController.phpView source
<?php
namespace Drupal\views_megarow\Controller;
use Drupal\Core\Controller\ControllerResolver;
use Drupal\views_megarow\Core\ViewsMegarowResponseRenderer;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
/**
* Default controller for Ajax requests.
*/
class ViewsMegarowController implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The controller resolver.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface
*/
protected $controllerResolver;
/**
* The Ajax response renderer.
*
* @var \Drupal\Core\Ajax\AjaxResponseRenderer
*/
protected $viewsMegarowRenderer;
/**
* Constructs a new AjaxController instance.
*
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
* The controller resolver.
* @param \Drupal\Core\Ajax\AjaxResponseRenderer $ajax_renderer
* The Ajax response renderer.
*/
public function __construct(ControllerResolver $controller_resolver, ViewsMegarowResponseRenderer $views_megarow_renderer) {
$this->controllerResolver = $controller_resolver;
$this->viewsMegarowRenderer = $views_megarow_renderer;
}
/**
* Controller method for Ajax content.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param callable $_content
* The callable that returns the content of the Ajax response.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* A response object.
*/
public function content(Request $request, $_content) {
$content = $this
->getContentResult($request, $_content);
return $this->viewsMegarowRenderer
->render($content);
}
/**
* 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;
}
}
Classes
Name | Description |
---|---|
ViewsMegarowController | Default controller for Ajax requests. |