You are here

public function DsDevelController::entityMarkup in Display Suite 8.3

Same name and namespace in other branches
  1. 8.4 modules/ds_devel/src/Controller/DsDevelController.php \Drupal\ds_devel\Controller\DsDevelController::entityMarkup()
  2. 8.2 modules/ds_devel/src/Controller/DsDevelController.php \Drupal\ds_devel\Controller\DsDevelController::entityMarkup()

Lists all instances of fields on any views.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: A RouteMatch object.

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

array The Views fields report page.

File

modules/ds_devel/src/Controller/DsDevelController.php, line 67

Class

DsDevelController
Returns responses for DS devel routes.

Namespace

Drupal\ds_devel\Controller

Code

public function entityMarkup(RouteMatchInterface $route_match, Request $request) {
  $parameter_name = $route_match
    ->getRouteObject()
    ->getOption('_devel_entity_type_id');
  $entity = $route_match
    ->getParameter($parameter_name);
  $entity_type_id = $entity
    ->getEntityTypeId();
  $key = $request->query
    ->get('key', 'default');
  $built_entity = $this
    ->entityTypeManager()
    ->getViewBuilder($entity_type_id)
    ->view($entity, $key);
  $markup = $this->renderer
    ->render($built_entity);
  $links = [];
  $active_view_modes = $this->entityDisplayRepository
    ->getViewModeOptionsByBundle($entity_type_id, $entity
    ->bundle());
  foreach ($active_view_modes as $id => $label) {
    $links[] = [
      'title' => $label,
      'url' => Url::fromRoute("entity.{$entity_type_id}.devel_markup", [
        $entity_type_id => $entity
          ->id(),
        'key' => $id,
      ]),
    ];
  }
  $build['links'] = [
    '#theme' => 'links',
    '#links' => $links,
    '#prefix' => '<hr/><div>',
    '#suffix' => '</div><hr />',
  ];
  $build['markup'] = [
    '#markup' => '<code><pre>' . Html::escape($markup) . '</pre></code>',
    '#cache' => [
      'max-age' => 0,
    ],
    '#allowed_tags' => [
      'code',
      'pre',
    ],
  ];
  return $build;
}