You are here

class ViewsMegarowController in Views Megarow 8

Default controller for Ajax requests.

Hierarchy

  • class \Drupal\views_megarow\Controller\ViewsMegarowController implements \Symfony\Component\DependencyInjection\ContainerAwareInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait

Expanded class hierarchy of ViewsMegarowController

1 string reference to 'ViewsMegarowController'
views_megarow.services.yml in ./views_megarow.services.yml
views_megarow.services.yml
1 service uses ViewsMegarowController
controller.views_megarow in ./views_megarow.services.yml
Drupal\views_megarow\Controller\ViewsMegarowController

File

src/Controller/ViewsMegarowController.php, line 14

Namespace

Drupal\views_megarow\Controller
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsMegarowController::$controllerResolver protected property The controller resolver.
ViewsMegarowController::$viewsMegarowRenderer protected property The Ajax response renderer.
ViewsMegarowController::content public function Controller method for Ajax content.
ViewsMegarowController::getContentResult public function Returns the result of invoking the sub-controller.
ViewsMegarowController::__construct public function Constructs a new AjaxController instance.