You are here

public function DsExtrasController::switchViewMode in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 modules/ds_extras/src/Controller/DsExtrasController.php \Drupal\ds_extras\Controller\DsExtrasController::switchViewMode()
  2. 8.3 modules/ds_extras/src/Controller/DsExtrasController.php \Drupal\ds_extras\Controller\DsExtrasController::switchViewMode()

Returns an node through JSON.

Parameters

Request $request: The global request object.

string $entityType: The type of the requested entity.

string $entityId: The id of the requested entity.

string $viewMode: The view mode you wish to render for the requested entity.

Return value

array The Views fields report page.

1 string reference to 'DsExtrasController::switchViewMode'
ds_extras.routing.yml in modules/ds_extras/ds_extras.routing.yml
modules/ds_extras/ds_extras.routing.yml

File

modules/ds_extras/src/Controller/DsExtrasController.php, line 31

Class

DsExtrasController
Returns responses for Display Suite Extra routes.

Namespace

Drupal\ds_extras\Controller

Code

public function switchViewMode(Request $request, $entityType, $entityId, $viewMode) {
  $response = new AjaxResponse();
  $entity = entity_load($entityType, $entityId);
  if ($entity
    ->access('view')) {
    $element = entity_view($entity, $viewMode);
    $content = \Drupal::service('renderer')
      ->render($element, FALSE);
    $response
      ->addCommand(new ReplaceCommand('.' . $request
      ->get('selector'), $content));
  }
  return $response;
}