You are here

public function WorkspaceListBuilder::render in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/WorkspaceListBuilder.php \Drupal\workspaces\WorkspaceListBuilder::render()
  2. 9 core/modules/workspaces/src/WorkspaceListBuilder.php \Drupal\workspaces\WorkspaceListBuilder::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/workspaces/src/WorkspaceListBuilder.php, line 200

Class

WorkspaceListBuilder
Defines a class to build a listing of workspace entities.

Namespace

Drupal\workspaces

Code

public function render() {
  $build = parent::render();
  if ($this
    ->isAjax()) {
    $this
      ->offCanvasRender($build);
  }
  else {

    // Add a row for switching to Live.
    $has_active_workspace = $this->workspaceManager
      ->hasActiveWorkspace();
    $row_live = [
      'data' => [
        'label' => [
          'data' => [
            '#markup' => $this
              ->t('Live'),
          ],
        ],
        'owner' => '',
        'operations' => [
          'data' => [
            '#type' => 'operations',
            '#links' => [
              'activate' => [
                'title' => 'Switch to Live',
                'weight' => 0,
                'url' => Url::fromRoute('workspaces.switch_to_live', [], [
                  'query' => $this
                    ->getDestinationArray(),
                ]),
              ],
            ],
            '#access' => $has_active_workspace,
          ],
        ],
      ],
    ];
    if (!$has_active_workspace) {
      $row_live['class'] = [
        'active-workspace',
        'active-workspace--default',
      ];
    }
    array_unshift($build['table']['#rows'], $row_live);
    $build['#attached'] = [
      'library' => [
        'workspaces/drupal.workspaces.overview',
      ],
    ];
  }
  return $build;
}