You are here

public function DsController::listDisplays in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 src/Controller/DsController.php \Drupal\ds\Controller\DsController::listDisplays()
  2. 8.3 src/Controller/DsController.php \Drupal\ds\Controller\DsController::listDisplays()

Lists all bundles per entity type.

Return value

array The Views fields report page.

1 string reference to 'DsController::listDisplays'
ds.routing.yml in ./ds.routing.yml
ds.routing.yml

File

src/Controller/DsController.php, line 23

Class

DsController
Returns responses for Display Suite UI routes.

Namespace

Drupal\ds\Controller

Code

public function listDisplays() {
  $build = array();

  // All entities.
  $entity_info = $this
    ->entityTypeManager()
    ->getDefinitions();

  // Move node to the top.
  if (isset($entity_info['node'])) {
    $node_entity = $entity_info['node'];
    unset($entity_info['node']);
    $entity_info = array_merge(array(
      'node' => $node_entity,
    ), $entity_info);
  }
  $field_ui_enabled = $this
    ->moduleHandler()
    ->moduleExists('field_ui');
  if (!$field_ui_enabled) {
    $build['no_field_ui'] = array(
      '#markup' => '<p>' . $this
        ->t('You need to enable Field UI to manage the displays of entities.') . '</p>',
      '#weight' => -10,
    );
  }
  if (isset($entity_info['comment'])) {
    $comment_entity = $entity_info['comment'];
    unset($entity_info['comment']);
    $entity_info['comment'] = $comment_entity;
  }
  foreach ($entity_info as $entity_type => $info) {
    $base_table = $info
      ->getBaseTable();
    if ($info
      ->get('field_ui_base_route') && !empty($base_table)) {
      $rows = array();
      $bundles = \Drupal::service('entity_type.bundle.info')
        ->getBundleInfo($entity_type);
      foreach ($bundles as $bundle_type => $bundle) {
        $row = array();
        $operations = array();
        $row[] = array(
          'data' => array(
            '#plain_text' => $bundle['label'],
          ),
        );
        if ($field_ui_enabled) {

          // Get the manage display URI.
          $route = FieldUI::getOverviewRouteInfo($entity_type, $bundle_type);
          if ($route) {
            $operations['manage_display'] = array(
              'title' => $this
                ->t('Manage display'),
              'url' => new Url("entity.entity_view_display.{$entity_type}.default", $route
                ->getRouteParameters()),
            );
          }
        }

        // Add operation links.
        if (!empty($operations)) {
          $row[] = array(
            'data' => array(
              '#type' => 'operations',
              '#subtype' => 'ds',
              '#links' => $operations,
            ),
          );
        }
        else {
          $row[] = array(
            'data' => '',
          );
        }
        $rows[] = $row;
      }
      if (!empty($rows)) {
        $header = array(
          array(
            'data' => $info
              ->getLabel(),
          ),
          array(
            'data' => $field_ui_enabled ? $this
              ->t('operations') : '',
            'class' => 'ds-display-list-options',
          ),
        );
        $build['list_' . $entity_type] = array(
          '#theme' => 'table',
          '#header' => $header,
          '#rows' => $rows,
        );
      }
    }
  }
  $build['#attached']['library'][] = 'ds/admin';
  return $build;
}