You are here

public function ViewListBuilder::render in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::render()

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

core/modules/views_ui/src/ViewListBuilder.php, line 193

Class

ViewListBuilder
Defines a class to build a listing of view entities.

Namespace

Drupal\views_ui

Code

public function render() {
  $entities = $this
    ->load();
  $list['#type'] = 'container';
  $list['#attributes']['id'] = 'views-entity-list';
  $list['#attached']['library'][] = 'core/drupal.ajax';
  $list['#attached']['library'][] = 'views_ui/views_ui.listing';
  $list['filters'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'table-filter',
        'js-show',
      ],
    ],
  ];
  $list['filters']['text'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Filter'),
    '#title_display' => 'invisible',
    '#size' => 60,
    '#placeholder' => $this
      ->t('Filter by view name, machine name, description, or display path'),
    '#attributes' => [
      'class' => [
        'views-filter-text',
      ],
      'data-table' => '.views-listing-table',
      'autocomplete' => 'off',
      'title' => $this
        ->t('Enter a part of the view name, machine name, description, or display path to filter by.'),
    ],
  ];
  $list['enabled']['heading']['#markup'] = '<h2>' . $this
    ->t('Enabled', [], [
    'context' => 'Plural',
  ]) . '</h2>';
  $list['disabled']['heading']['#markup'] = '<h2>' . $this
    ->t('Disabled', [], [
    'context' => 'Plural',
  ]) . '</h2>';
  foreach ([
    'enabled',
    'disabled',
  ] as $status) {
    $list[$status]['#type'] = 'container';
    $list[$status]['#attributes'] = [
      'class' => [
        'views-list-section',
        $status,
      ],
    ];
    $list[$status]['table'] = [
      '#theme' => 'views_ui_views_listing_table',
      '#headers' => $this
        ->buildHeader(),
      '#attributes' => [
        'class' => [
          'views-listing-table',
          $status,
        ],
      ],
    ];
    foreach ($entities[$status] as $entity) {
      $list[$status]['table']['#rows'][$entity
        ->id()] = $this
        ->buildRow($entity);
    }
  }
  $list['enabled']['table']['#empty'] = $this
    ->t('There are no enabled views.');
  $list['disabled']['table']['#empty'] = $this
    ->t('There are no disabled views.');
  return $list;
}