You are here

class DsDevelController in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 modules/ds_devel/src/Controller/DsDevelController.php \Drupal\ds_devel\Controller\DsDevelController
  2. 8.3 modules/ds_devel/src/Controller/DsDevelController.php \Drupal\ds_devel\Controller\DsDevelController

Returns responses for Views UI routes.

Hierarchy

Expanded class hierarchy of DsDevelController

File

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

Namespace

Drupal\ds_devel\Controller
View source
class DsDevelController {

  /**
   * Lists all instances of fields on any views.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *    A RouteMatch object.
   *
   * @return array
   *   The Views fields report page.
   */
  public function entityMarkup(RouteMatchInterface $route_match) {
    $parameter_name = $route_match
      ->getRouteObject()
      ->getOption('_devel_entity_type_id');
    $entity = $route_match
      ->getParameter($parameter_name);
    $entity_type_id = $entity
      ->getEntityTypeId();
    $key = \Drupal::request()
      ->get('key', 'default');
    $builded_entity = entity_view($entity, $key);
    $markup = \Drupal::service('renderer')
      ->render($builded_entity);
    $links = array();
    $active_view_modes = \Drupal::service('entity_display.repository')
      ->getViewModeOptionsByBundle($entity_type_id, $entity
      ->bundle());
    foreach ($active_view_modes as $id => $label) {
      $links[] = array(
        'title' => $label,
        'url' => Url::fromRoute("entity.{$entity_type_id}.devel_markup", array(
          $entity_type_id => $entity
            ->id(),
          'key' => $id,
        )),
      );
    }
    $build['links'] = array(
      '#theme' => 'links',
      '#links' => $links,
      '#prefix' => '<hr/><div>',
      '#suffix' => '</div><hr />',
    );
    $build['markup'] = [
      '#markup' => '<code><pre>' . Html::escape($markup) . '</pre></code>',
      '#cache' => array(
        'max-age' => 0,
      ),
      '#allowed_tags' => [
        'code',
        'pre',
      ],
    ];
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DsDevelController::entityMarkup public function Lists all instances of fields on any views.