diff --git a/core/modules/workspace/src/Form/DeploymentForm.php b/core/modules/workspace/src/Form/DeploymentForm.php index 0889f5c537..571110affe 100644 --- a/core/modules/workspace/src/Form/DeploymentForm.php +++ b/core/modules/workspace/src/Form/DeploymentForm.php @@ -33,19 +33,20 @@ public function buildForm(array $form, FormStateInterface $form_state, Workspace '#value' => $workspace->id(), ]; - $form['update'] = [ - '#type' => 'submit', - '#value' => $this->t('Update'), - '#submit' => [[$this, 'updateHandler']], - ]; - $form['deploy'] = [ '#type' => 'submit', '#value' => $this->t('Deploy to %upstream', ['%upstream' => $upstream_plugin->getLabel()]), - '#submit' => [[$this, 'deployHandler']], '#attributes' => [ 'class' => ['primary', 'button--primary'], ], + '#weight' => 1, + ]; + + $form['update'] = [ + '#type' => 'submit', + '#value' => $this->t('Update'), + '#submit' => ['::updateHandler'], + '#weight' => 0, ]; return $form; @@ -71,10 +72,9 @@ public function updateHandler(array &$form, FormStateInterface $form_state) { } /** - * @param array $form - * @param \Drupal\Core\Form\FormStateInterface $form_state + * {@inheritdoc} */ - public function deployHandler(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { $workspace = Workspace::load($form_state->getValue('workspace_id')); $upstream_manager = \Drupal::service('workspace.upstream_manager'); try { @@ -89,11 +89,4 @@ public function deployHandler(array &$form, FormStateInterface $form_state) { } } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - // Submission handled in custom handlers. - } - } diff --git a/core/modules/workspace/tests/src/Functional/ReplicationTest.php b/core/modules/workspace/tests/src/Functional/ReplicationTest.php index 4da13555c2..eb3f39a80a 100644 --- a/core/modules/workspace/tests/src/Functional/ReplicationTest.php +++ b/core/modules/workspace/tests/src/Functional/ReplicationTest.php @@ -52,6 +52,7 @@ public function setUp() { 'administer node display', 'administer node fields', 'administer node form display', + 'administer workspaces', ]; $test_user = $this->drupalCreateUser($permissions); $this->drupalLogin($test_user); @@ -72,7 +73,7 @@ public function testNodeReplication() { $page->fillField('Title', 'Test node'); $page->findButton(t('Save'))->click(); $page = $session->getPage(); - $page->hasContent("Test node has been created"); + $this->assertTrue($page->hasContent("Test node has been created")); $this->drupalGet('/node/1/edit'); $session = $this->getSession(); $this->assertEquals(200, $session->getStatusCode()); @@ -80,14 +81,13 @@ public function testNodeReplication() { $this->assertEquals($dev->id(), $this->getOneEntityByLabel('node', 'Test node')->workspace->target_id); - /** @var \Drupal\workspace\Replication\ReplicationManager $replicator */ - $replicator = \Drupal::service('workspace.replication_manager'); - /** @var \Drupal\workspace\UpstreamManager $upstream */ - $upstream = \Drupal::service('workspace.upstream_manager'); - $replicator->replicate( - $upstream->createInstance('workspace:' . $dev->id()), - $upstream->createInstance('workspace:' . $stage->id()) - ); + $this->drupalGet('/admin/structure/workspace/' . $dev->id() . '/deployment'); + $session = $this->getSession(); + $page = $session->getPage(); + $this->assertEquals(200, $session->getStatusCode()); + $this->assertTrue($page->hasContent('Update Dev from Stage or deploy to Stage.')); + $page->findButton('edit-deploy')->click(); + $session->getPage()->hasContent('Successful deployment'); $this->switchToWorkspace($stage); $this->assertEquals($stage->id(), $this->getOneEntityByLabel('node', 'Test node')->workspace->target_id); @@ -103,10 +103,13 @@ public function testNodeReplication() { $this->assertEquals($stage->id(), $this->getOneEntityByLabel('node', 'Test stage node')->workspace->target_id); - $replicator->replicate( - $upstream->createInstance('workspace:' . $stage->id()), - $upstream->createInstance('workspace:' . $live->id()) - ); + $this->drupalGet('/admin/structure/workspace/' . $stage->id() . '/deployment'); + $session = $this->getSession(); + $page = $session->getPage(); + $this->assertEquals(200, $session->getStatusCode()); + $this->assertTrue($page->hasContent('Update Stage from Live or deploy to Live.')); + $page->findButton('edit-deploy')->click(); + $session->getPage()->hasContent('Successful deployment'); $this->switchToWorkspace($live); $this->assertEquals($live->id(), $this->getOneEntityByLabel('node', 'Test node')->workspace->target_id); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php b/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php index fdb77e52c1..cd74b3f140 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\workspace\Functional; +use Behat\Mink\Element\DocumentElement; use Drupal\node\Entity\NodeType; use Drupal\workspace\Entity\WorkspaceInterface; @@ -74,9 +75,13 @@ protected function createWorkspaceThroughUI($label, $machine_name) { $session = $this->getSession(); $this->assertSession()->statusCodeEquals(200); + /** @var DocumentElement $page */ $page = $session->getPage(); $page->fillField('label', $label); $page->fillField('machine_name', $machine_name); + if ($machine_name == 'dev') { + $page->selectFieldOption('upstream', 'workspace:stage'); + } $page->findButton(t('Save'))->click(); $session->getPage()->hasContent("$label ($machine_name)"); diff --git a/core/modules/workspace/workspace.module b/core/modules/workspace/workspace.module index 6354b7c67f..cd1057ab68 100644 --- a/core/modules/workspace/workspace.module +++ b/core/modules/workspace/workspace.module @@ -85,7 +85,7 @@ function workspace_views_query_alter(ViewExecutable $view, QueryPluginBase $quer } $entity_type = $view->getBaseEntityType(); - if (!$workspace_manager->entityTypeCanBelongToWorkspaces($entity_type)) { + if (empty($entity_type) || !$workspace_manager->entityTypeCanBelongToWorkspaces($entity_type)) { return; } diff --git a/core/modules/workspace/workspace.permissions.yml b/core/modules/workspace/workspace.permissions.yml index 475d7e541e..b1ee465ee4 100644 --- a/core/modules/workspace/workspace.permissions.yml +++ b/core/modules/workspace/workspace.permissions.yml @@ -1,29 +1,26 @@ +administer workspaces: + title: Administer workspaces + create_workspace: title: Create a new workspace view_own_workspace: title: View own workspace - description: View a workspace owned by the user. view_any_workspace: title: View any workspace - description: View any workspace, regardless of ownership. edit_own_workspace: title: Edit own workspace - description: Make changes to workspaces owned by the user. edit_any_workspace: title: Edit any workspace - description: Make changes to any workspace, regardless of ownership. delete_own_workspace: title: Delete own workspace - description: Delete a workspace owned by the user and all content revisions within it. delete_any_workspace: title: Delete any workspace - description: Delete a workspace and all content revisions within it, regardless of ownership. bypass_entity_access_own_workspace: title: Bypass content entity access in own workspace @@ -32,11 +29,9 @@ bypass_entity_access_own_workspace: view_revision_trees: title: View revision trees - description: View the revision tree for any entities. update any workspace from upstream: title: Update any workspace from upstream - description: Update any workspace with the latest changes from its upstream workspace. permission_callbacks: - Drupal\workspace\EntityAccess::workspacePermissions