Unverified Commit ea475b41 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3092553 by amateescu, dixon_, shaal, xjm, ckrina, jrockowitz, webchick,...

Issue #3092553 by amateescu, dixon_, shaal, xjm, ckrina, jrockowitz, webchick, worldlinemine: Add a row for switching to the live workspace in the Workspaces listing UI
parent 846675a5
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public function buildRow(EntityInterface $entity) {

    $active_workspace = $this->workspaceManager->getActiveWorkspace();
    if ($active_workspace && $entity->id() === $active_workspace->id()) {
      $row['class'] = 'active-workspace';
      $row['class'] = ['active-workspace', 'active-workspace--not-default'];
    }
    return $row;
  }
@@ -195,6 +195,37 @@ public function render() {
      $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'],
      ];
+36 −0
Original line number Diff line number Diff line
@@ -213,4 +213,40 @@ public function testDeleteWorkspaceWithExistingContent() {
    $page->hasContent('The workspace May 4 has been deleted.');
  }

  /**
   * Tests the Workspaces listing UI.
   */
  public function testWorkspaceList() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // Login and create a workspace.
    $this->drupalLogin($this->editor1);
    $this->createWorkspaceThroughUi('Summer event', 'summer_event');

    // Check that Live is the current active workspace.
    $this->drupalGet('/admin/config/workflow/workspaces');
    $this->assertSession()->statusCodeEquals(200);

    $active_workspace_row = $page->find('css', '.active-workspace');
    $this->assertTrue($active_workspace_row->hasClass('active-workspace--default'));
    $this->assertEquals('Live', $active_workspace_row->find('css', 'td:first-of-type')->getText());

    // The 'Switch to Live' operation is not shown when 'Live' is the active
    // workspace.
    $assert_session->linkNotExists('Switch to Live');

    // Switch to another workspace and check that it has been marked as active.
    $page->clickLink('Switch to Summer event');
    $page->pressButton('Confirm');

    $active_workspace_row = $page->find('css', '.active-workspace');
    $this->assertTrue($active_workspace_row->hasClass('active-workspace--not-default'));
    $this->assertEquals('Summer event', $active_workspace_row->find('css', 'td:first-of-type')->getText());

    // 'Live' is no longer the active workspace, so it's 'Switch to Live'
    // operation should be visible now.
    $assert_session->linkExists('Switch to Live');
  }

}