You are here

class ContextualController in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/contextual/src/ContextualController.php \Drupal\contextual\ContextualController

Returns responses for Contextual module routes.

Hierarchy

Expanded class hierarchy of ContextualController

File

core/modules/contextual/src/ContextualController.php, line 19
Contains \Drupal\contextual\ContextualController.

Namespace

Drupal\contextual
View source
class ContextualController implements ContainerAwareInterface {
  use ContainerAwareTrait;

  /**
   * Returns the requested rendered contextual links.
   *
   * Given a list of contextual links IDs, render them. Hence this must be
   * robust to handle arbitrary input.
   *
   * @see contextual_preprocess()
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   */
  public function render(Request $request) {
    $ids = $request->request
      ->get('ids');
    if (!isset($ids)) {
      throw new BadRequestHttpException(t('No contextual ids specified.'));
    }
    $rendered = array();
    foreach ($ids as $id) {
      $element = array(
        '#type' => 'contextual_links',
        '#contextual_links' => _contextual_id_to_links($id),
      );
      $rendered[$id] = $this->container
        ->get('renderer')
        ->renderRoot($element);
    }
    return new JsonResponse($rendered);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerAwareTrait::$container protected property
ContainerAwareTrait::setContainer public function Sets the Container associated with this Controller.
ContextualController::render public function Returns the requested rendered contextual links.