workspaceManager = $workspace_manager; } /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('workspaces.manager') ); } /** * {@inheritdoc} */ public function buildHeader() { $header['label'] = $this->t('Workspace'); $header['uid'] = $this->t('Owner'); return $header + parent::buildHeader(); } /** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\workspaces\WorkspaceInterface $entity */ $row['data'] = [ 'label' => $entity->label(), 'owner' => $entity->getOwner()->getDisplayname(), ]; $row['data'] = $row['data'] + parent::buildRow($entity); $active_workspace = $this->workspaceManager->getActiveWorkspace(); if ($entity->id() === $active_workspace->id()) { $row['class'] = 'active-workspace'; } return $row; } /** * {@inheritdoc} */ public function getDefaultOperations(EntityInterface $entity) { /** @var \Drupal\workspaces\WorkspaceInterface $entity */ $operations = parent::getDefaultOperations($entity); if (isset($operations['edit'])) { $operations['edit']['query']['destination'] = $entity->toUrl('collection')->toString(); } $active_workspace = $this->workspaceManager->getActiveWorkspace(); if ($entity->id() != $active_workspace->id()) { $operations['activate'] = [ 'title' => $this->t('Switch to @workspace', ['@workspace' => $entity->label()]), // Use a weight lower than the one of the 'Edit' operation because we // want the 'Activate' operation to be the primary operation. 'weight' => 0, 'url' => $entity->toUrl('activate-form', ['query' => ['destination' => $entity->toUrl('collection')->toString()]]), ]; } if (!$entity->isDefaultWorkspace()) { $operations['deploy'] = [ 'title' => $this->t('Deploy content'), // The 'Deploy' operation should be the default one for the currently // active workspace. 'weight' => ($entity->id() == $active_workspace->id()) ? 0 : 20, 'url' => $entity->toUrl('deploy-form', ['query' => ['destination' => $entity->toUrl('collection')->toString()]]), ]; } return $operations; } /** * {@inheritdoc} */ public function load() { $entities = parent::load(); // Make the active workspace more visible by moving it first in the list. $active_workspace = $this->workspaceManager->getActiveWorkspace(); $entities = [$active_workspace->id() => $entities[$active_workspace->id()]] + $entities; return $entities; } /** * {@inheritdoc} */ public function render() { $build = parent::render(); if ($this->isAjax()) { $this->offCanvasRender($build); } else { $build['#attached'] = [ 'library' => ['workspaces/drupal.workspaces.overview'], ]; } return $build; } /** * Renders the off canvas elements. * * @param array $build * A render array. */ protected function offCanvasRender(array &$build) { $active_workspace = $this->workspaceManager->getActiveWorkspace(); $row_count = count($build['table']['#rows']); $build['active_workspace'] = [ '#type' => 'container', '#weight' => -20, '#attributes' => [ 'class' => [ 'active-workspace', $active_workspace->isDefaultWorkspace() ? 'active-workspace--default' : 'active-workspace--not-default', 'active-workspace--' . $active_workspace->id(), ], ], 'label' => [ '#type' => 'label', '#prefix' => '