diff --git a/core/modules/workspaces/config/install/core.entity_form_display.workspace.workspace.deploy.yml b/core/modules/workspaces/config/install/core.entity_form_display.workspace.workspace.deploy.yml deleted file mode 100644 index 201d63623544eb6344319db651ad87aa5396d200..0000000000000000000000000000000000000000 --- a/core/modules/workspaces/config/install/core.entity_form_display.workspace.workspace.deploy.yml +++ /dev/null @@ -1,15 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - core.entity_form_mode.workspace.deploy - module: - - workspaces -id: workspace.workspace.deploy -targetEntityType: workspace -bundle: workspace -mode: deploy -content: { } -hidden: - parent: true - uid: true diff --git a/core/modules/workspaces/config/install/core.entity_form_mode.workspace.deploy.yml b/core/modules/workspaces/config/install/core.entity_form_mode.workspace.deploy.yml deleted file mode 100644 index 789616c8bc382418741305c54c70660c695274dd..0000000000000000000000000000000000000000 --- a/core/modules/workspaces/config/install/core.entity_form_mode.workspace.deploy.yml +++ /dev/null @@ -1,9 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - workspaces -id: workspace.deploy -label: Deploy -targetEntityType: workspace -cache: true diff --git a/core/modules/workspaces/src/Entity/Workspace.php b/core/modules/workspaces/src/Entity/Workspace.php index 3236e3ccbcad0f0fe0eaa0e8814688a27d908c41..527418da6e288a18a94e15aeac109057ac948d34 100644 --- a/core/modules/workspaces/src/Entity/Workspace.php +++ b/core/modules/workspaces/src/Entity/Workspace.php @@ -36,7 +36,6 @@ * "edit" = "\Drupal\workspaces\Form\WorkspaceForm", * "delete" = "\Drupal\workspaces\Form\WorkspaceDeleteForm", * "activate" = "\Drupal\workspaces\Form\WorkspaceActivateForm", - * "deploy" = "\Drupal\workspaces\Form\WorkspaceDeployForm", * }, * }, * admin_permission = "administer workspaces", @@ -58,7 +57,6 @@ * "edit-form" = "/admin/config/workflow/workspaces/manage/{workspace}/edit", * "delete-form" = "/admin/config/workflow/workspaces/manage/{workspace}/delete", * "activate-form" = "/admin/config/workflow/workspaces/manage/{workspace}/activate", - * "deploy-form" = "/admin/config/workflow/workspaces/manage/{workspace}/deploy", * "collection" = "/admin/config/workflow/workspaces", * }, * ) diff --git a/core/modules/workspaces/src/Form/WorkspaceDeployForm.php b/core/modules/workspaces/src/Form/WorkspaceDeployForm.php deleted file mode 100644 index cb988ea8878569a249b7abd8d5a31ad13daec1f0..0000000000000000000000000000000000000000 --- a/core/modules/workspaces/src/Form/WorkspaceDeployForm.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php - -namespace Drupal\workspaces\Form; - -use Drupal\Component\Datetime\TimeInterface; -use Drupal\Core\Entity\ContentEntityForm; -use Drupal\Core\Entity\EntityRepositoryInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Messenger\MessengerInterface; -use Drupal\workspaces\WorkspaceAccessException; -use Drupal\workspaces\WorkspaceOperationFactory; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides the workspace deploy form. - */ -class WorkspaceDeployForm extends ContentEntityForm implements WorkspaceFormInterface { - - /** - * The workspace entity. - * - * @var \Drupal\workspaces\WorkspaceInterface - */ - protected $entity; - - /** - * The messenger service. - * - * @var \Drupal\Core\Messenger\MessengerInterface - */ - protected $messenger; - - /** - * The workspace operation factory. - * - * @var \Drupal\workspaces\WorkspaceOperationFactory - */ - protected $workspaceOperationFactory; - - /** - * Constructs a new WorkspaceDeployForm. - * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository - * The entity repository service. - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info - * The entity type bundle service. - * @param \Drupal\Component\Datetime\TimeInterface $time - * The time service. - * @param \Drupal\Core\Messenger\MessengerInterface $messenger - * The messenger service. - * @param \Drupal\workspaces\WorkspaceOperationFactory $workspace_operation_factory - * The workspace operation factory service. - */ - public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, MessengerInterface $messenger, WorkspaceOperationFactory $workspace_operation_factory) { - parent::__construct($entity_repository, $entity_type_bundle_info, $time); - $this->messenger = $messenger; - $this->workspaceOperationFactory = $workspace_operation_factory; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.repository'), - $container->get('entity_type.bundle.info'), - $container->get('datetime.time'), - $container->get('messenger'), - $container->get('workspaces.operation_factory') - ); - } - - /** - * {@inheritdoc} - */ - public function form(array $form, FormStateInterface $form_state) { - $form = parent::form($form, $form_state); - - $workspace_publisher = $this->workspaceOperationFactory->getPublisher($this->entity); - - $args = [ - '%source_label' => $this->entity->label(), - '%target_label' => $workspace_publisher->getTargetLabel(), - ]; - $form['#title'] = $this->t('Deploy %source_label workspace', $args); - - // List the changes that can be pushed. - if ($source_rev_diff = $workspace_publisher->getDifferringRevisionIdsOnSource()) { - $total_count = $workspace_publisher->getNumberOfChangesOnSource(); - $form['deploy'] = [ - '#theme' => 'item_list', - '#title' => $this->formatPlural($total_count, 'There is @count item that can be deployed from %source_label to %target_label', 'There are @count items that can be deployed from %source_label to %target_label', $args), - '#items' => [], - '#total_count' => $total_count, - ]; - foreach ($source_rev_diff as $entity_type_id => $revision_difference) { - $form['deploy']['#items'][$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($revision_difference)); - } - } - - // If there are no changes to push or pull, show an informational message. - if (!isset($form['deploy']) && !isset($form['refresh'])) { - $form['help'] = [ - '#markup' => $this->t('There are no changes that can be deployed from %source_label to %target_label.', $args), - ]; - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function actions(array $form, FormStateInterface $form_state) { - $elements = parent::actions($form, $form_state); - unset($elements['delete']); - - $workspace_publisher = $this->workspaceOperationFactory->getPublisher($this->entity); - - if (isset($form['deploy'])) { - $total_count = $form['deploy']['#total_count']; - $elements['submit']['#value'] = $this->formatPlural($total_count, 'Deploy @count item to @target', 'Deploy @count items to @target', ['@target' => $workspace_publisher->getTargetLabel()]); - $elements['submit']['#submit'] = ['::submitForm', '::deploy']; - } - else { - // Do not allow the 'Deploy' operation if there's nothing to push. - $elements['submit']['#value'] = $this->t('Deploy'); - $elements['submit']['#disabled'] = TRUE; - } - - $elements['cancel'] = [ - '#type' => 'link', - '#title' => $this->t('Cancel'), - '#attributes' => ['class' => ['button']], - '#url' => $this->entity->toUrl('collection'), - ]; - - return $elements; - } - - /** - * Form submission handler; deploys the content to the workspace's target. - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - public function deploy(array &$form, FormStateInterface $form_state) { - $workspace = $this->entity; - - try { - $workspace->publish(); - $this->messenger->addMessage($this->t('Successful deployment.')); - } - catch (WorkspaceAccessException $e) { - $this->messenger->addMessage($e->getMessage(), 'error'); - } - catch (\Exception $e) { - $this->messenger->addMessage($this->t('Deployment failed. All errors have been logged.'), 'error'); - } - } - -} diff --git a/core/modules/workspaces/src/Form/WorkspacePublishForm.php b/core/modules/workspaces/src/Form/WorkspacePublishForm.php new file mode 100644 index 0000000000000000000000000000000000000000..55f82aa256044922f0bce1f6b1bae4117f77762e --- /dev/null +++ b/core/modules/workspaces/src/Form/WorkspacePublishForm.php @@ -0,0 +1,157 @@ +<?php + +namespace Drupal\workspaces\Form; + +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Form\ConfirmFormBase; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; +use Drupal\workspaces\WorkspaceAccessException; +use Drupal\workspaces\WorkspaceInterface; +use Drupal\workspaces\WorkspaceOperationFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Provides the workspace publishing form. + */ +class WorkspacePublishForm extends ConfirmFormBase implements WorkspaceFormInterface, ContainerInjectionInterface { + + /** + * The workspace that will be published. + * + * @var \Drupal\workspaces\WorkspaceInterface + */ + protected $workspace; + + /** + * The workspace operation factory. + * + * @var \Drupal\workspaces\WorkspaceOperationFactory + */ + protected $workspaceOperationFactory; + + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Constructs a new WorkspacePublishForm. + * + * @param \Drupal\workspaces\WorkspaceOperationFactory $workspace_operation_factory + * The workspace operation factory service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + */ + public function __construct(WorkspaceOperationFactory $workspace_operation_factory, EntityTypeManagerInterface $entity_type_manager) { + $this->workspaceOperationFactory = $workspace_operation_factory; + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('workspaces.operation_factory'), + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'workspace_publish_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, WorkspaceInterface $workspace = NULL) { + $this->workspace = $workspace; + + $form = parent::buildForm($form, $form_state); + + $workspace_publisher = $this->workspaceOperationFactory->getPublisher($this->workspace); + + $args = [ + '%source_label' => $this->workspace->label(), + '%target_label' => $workspace_publisher->getTargetLabel(), + ]; + $form['#title'] = $this->t('Publish %source_label workspace', $args); + + // List the changes that can be pushed. + if ($source_rev_diff = $workspace_publisher->getDifferringRevisionIdsOnSource()) { + $total_count = $workspace_publisher->getNumberOfChangesOnSource(); + $form['description'] = [ + '#theme' => 'item_list', + '#title' => $this->formatPlural($total_count, 'There is @count item that can be published from %source_label to %target_label', 'There are @count items that can be published from %source_label to %target_label', $args), + '#items' => [], + '#total_count' => $total_count, + ]; + foreach ($source_rev_diff as $entity_type_id => $revision_difference) { + $form['description']['#items'][$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($revision_difference)); + } + + $form['actions']['submit']['#value'] = $this->formatPlural($total_count, 'Publish @count item to @target', 'Publish @count items to @target', ['@target' => $workspace_publisher->getTargetLabel()]); + } + else { + // If there are no changes to push or pull, show an informational message. + $form['help'] = [ + '#markup' => $this->t('There are no changes that can be published from %source_label to %target_label.', $args), + ]; + + // Do not allow the 'Publish' operation if there's nothing to publish. + $form['actions']['submit']['#value'] = $this->t('Publish'); + $form['actions']['submit']['#disabled'] = TRUE; + } + + return $form; + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return $this->t('Would you like to publish the contents of the %label workspace?', [ + '%label' => $this->workspace->label(), + ]); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('Publish workspace contents.'); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return Url::fromRoute('entity.workspace.collection', [], ['query' => \Drupal::destination()->getAsArray()]); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $workspace = $this->workspace; + + try { + $workspace->publish(); + $this->messenger()->addMessage($this->t('Successful publication.')); + } + catch (WorkspaceAccessException $e) { + $this->messenger()->addMessage($e->getMessage(), 'error'); + } + catch (\Exception $e) { + $this->messenger()->addMessage($this->t('Publication failed. All errors have been logged.'), 'error'); + } + } + +} diff --git a/core/modules/workspaces/src/WorkspaceListBuilder.php b/core/modules/workspaces/src/WorkspaceListBuilder.php index 23aa6521021cb0a8b6ee8cc5899fa3d6db3034e1..69de069fcef05332d10ddb0c8eebe38beb455e9e 100644 --- a/core/modules/workspaces/src/WorkspaceListBuilder.php +++ b/core/modules/workspaces/src/WorkspaceListBuilder.php @@ -150,12 +150,15 @@ public function getDefaultOperations(EntityInterface $entity) { } if (!$entity->hasParent()) { - $operations['deploy'] = [ - 'title' => $this->t('Deploy content'), - // The 'Deploy' operation should be the default one for the currently + $operations['publish'] = [ + 'title' => $this->t('Publish content'), + // The 'Publish' operation should be the default one for the currently // active workspace. 'weight' => ($active_workspace && $entity->id() == $active_workspace->id()) ? 0 : 20, - 'url' => $entity->toUrl('deploy-form', ['query' => ['destination' => $entity->toUrl('collection')->toString()]]), + 'url' => Url::fromRoute('entity.workspace.publish_form', + ['workspace' => $entity->id()], + ['query' => ['destination' => $entity->toUrl('collection')->toString()]] + ), ]; } else { @@ -256,10 +259,13 @@ protected function offCanvasRender(array &$build) { ], ]; if (!$active_workspace->hasParent()) { - $build['active_workspace']['actions']['deploy'] = [ + $build['active_workspace']['actions']['publish'] = [ '#type' => 'link', - '#title' => $this->t('Deploy content'), - '#url' => $active_workspace->toUrl('deploy-form', ['query' => ['destination' => $active_workspace->toUrl('collection')->toString()]]), + '#title' => $this->t('Publish content'), + '#url' => Url::fromRoute('entity.workspace.publish_form', + ['workspace' => $active_workspace->id()], + ['query' => ['destination' => $active_workspace->toUrl('collection')->toString()]] + ), '#attributes' => [ 'class' => ['button', 'active-workspace__button'], ], diff --git a/core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php b/core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php index aa8d415b8bb1ce2a3d4f304adddd7ead7a412576..3922f98e5637160c618a4d4621b276e7574a8b19 100644 --- a/core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php @@ -89,7 +89,7 @@ public function testConcurrentEditing() { $this->assertCount(1, $violations); $this->assertEquals('The content is being edited in the <em class="placeholder">Vultures</em> workspace. As a result, your changes cannot be saved.', $violations->get(0)->getMessage()); - // Deploy the changes from the 'Vultures' workspace and check that the node + // Publish the changes from the 'Vultures' workspace and check that the node // can be edited again in other workspaces. $vultures->publish(); $this->switchToWorkspace($gravity); diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php index fc647174aa1df6ada1c9c7317476e4aca9d6214b..caec3d16f80f70578996b32b3e3395ca3afa9fea 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php @@ -18,7 +18,7 @@ use Drupal\workspaces\WorkspaceAccessException; /** - * Tests a complete deployment scenario across different workspaces. + * Tests a complete publishing scenario across different workspaces. * * @group #slow * @group workspaces @@ -110,7 +110,7 @@ protected function setUp(): void { } /** - * Tests various scenarios for creating and deploying content in workspaces. + * Tests various scenarios for creating and publishing content in workspaces. */ public function testWorkspaces() { $this->initializeWorkspacesModule(); @@ -280,7 +280,7 @@ public function testWorkspaces() { $test_scenarios['add_published_node_in_stage'] = $revision_state; $expected_workspace_association['add_published_node_in_stage'] = ['stage' => [3, 4, 5, 7]]; - // Deploying 'stage' to 'live' should simply make the latest revisions in + // Publishing 'stage' to 'live' should simply make the latest revisions in // 'stage' the default ones in 'live'. $revision_state = array_replace_recursive($revision_state, [ 'live' => [ @@ -337,7 +337,7 @@ public function testWorkspaces() { $this->assertWorkspaceStatus($test_scenarios['add_published_node_in_stage'], 'node'); $this->assertWorkspaceAssociation($expected_workspace_association['add_published_node_in_stage'], 'node'); - // Deploy 'stage' to 'live'. + // Publish 'stage' to 'live'. /** @var \Drupal\workspaces\WorkspacePublisher $workspace_publisher */ $workspace_publisher = \Drupal::service('workspaces.operation_factory')->getPublisher($this->workspaces['stage']); @@ -1003,7 +1003,7 @@ public function testFormCacheForRegularForms() { } /** - * Test a deployment with fields in dedicated table storage. + * Test publishing with fields in dedicated table storage. */ public function testPublishWorkspaceDedicatedTableStorage() { $this->initializeWorkspacesModule(); diff --git a/core/modules/workspaces/workspaces.link_relation_types.yml b/core/modules/workspaces/workspaces.link_relation_types.yml index 6036375af92aae8711809d0308548b35b6ef663e..3527a5b9534d3d21af8d8ce031a752ab818888e8 100644 --- a/core/modules/workspaces/workspaces.link_relation_types.yml +++ b/core/modules/workspaces/workspaces.link_relation_types.yml @@ -3,6 +3,3 @@ activate-form: uri: https://drupal.org/link-relations/activate-form description: A form where a workspace can be activated. -deploy-form: - uri: https://drupal.org/link-relations/deploy-form - description: A form where a workspace can be deployed. diff --git a/core/modules/workspaces/workspaces.routing.yml b/core/modules/workspaces/workspaces.routing.yml index d020a4edaf833fec9e471d54685d43ea4a1f7071..751e778ae59acdfd8901f4043432aa93c4be79db 100644 --- a/core/modules/workspaces/workspaces.routing.yml +++ b/core/modules/workspaces/workspaces.routing.yml @@ -16,13 +16,16 @@ entity.workspace.activate_form: requirements: _entity_access: 'workspace.view' -entity.workspace.deploy_form: - path: '/admin/config/workflow/workspaces/manage/{workspace}/deploy' +entity.workspace.publish_form: + path: '/admin/config/workflow/workspaces/manage/{workspace}/publish' defaults: - _entity_form: 'workspace.deploy' - _title: 'Deploy Workspace' + _form: '\Drupal\workspaces\Form\WorkspacePublishForm' + _title: 'Publish workspace' options: _admin_route: TRUE + parameters: + workspace: + type: entity:workspace requirements: _permission: 'administer workspaces'