Skip to content
Snippets Groups Projects
Commit d84f2c9d authored by catch's avatar catch
Browse files

Issue #3278377 by amateescu, s_leu, smustgrave, pooja saraah, rkoller,...

Issue #3278377 by amateescu, s_leu, smustgrave, pooja saraah, rkoller, simohell: Creating a new workspace should also switch to it
parent e7159707
Branches
Tags
31 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #124110 canceled
Pipeline: drupal

#124113

    ......@@ -2,14 +2,11 @@
    namespace Drupal\workspaces\Form;
    use Drupal\Component\Datetime\TimeInterface;
    use Drupal\Core\Entity\ContentEntityForm;
    use Drupal\Core\Entity\EntityConstraintViolationListInterface;
    use Drupal\Core\Entity\EntityRepositoryInterface;
    use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Messenger\MessengerInterface;
    use Drupal\Core\Url;
    use Drupal\workspaces\WorkspaceManagerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    /**
    ......@@ -25,39 +22,17 @@ class WorkspaceForm extends ContentEntityForm implements WorkspaceFormInterface
    protected $entity;
    /**
    * The messenger service.
    *
    * @var \Drupal\Core\Messenger\MessengerInterface
    * The workspace manager.
    */
    protected $messenger;
    /**
    * Constructs a new WorkspaceForm.
    *
    * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
    * The entity repository service.
    * @param \Drupal\Core\Messenger\MessengerInterface $messenger
    * The messenger service.
    * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
    * The entity type bundle service.
    * @param \Drupal\Component\Datetime\TimeInterface $time
    * The time service.
    */
    public function __construct(EntityRepositoryInterface $entity_repository, MessengerInterface $messenger, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
    parent::__construct($entity_repository, $entity_type_bundle_info, $time);
    $this->messenger = $messenger;
    }
    protected WorkspaceManagerInterface $workspaceManager;
    /**
    * {@inheritdoc}
    */
    public static function create(ContainerInterface $container) {
    return new static(
    $container->get('entity.repository'),
    $container->get('messenger'),
    $container->get('entity_type.bundle.info'),
    $container->get('datetime.time')
    );
    $instance = parent::create($container);
    $instance->workspaceManager = $container->get('workspaces.manager');
    return $instance;
    }
    /**
    ......@@ -120,6 +95,27 @@ protected function flagViolations(EntityConstraintViolationListInterface $violat
    parent::flagViolations($violations, $form, $form_state);
    }
    /**
    * {@inheritdoc}
    */
    protected function actions(array $form, FormStateInterface $form_state): array {
    $actions = parent::actions($form, $form_state);
    // When adding a new workspace, the default action should also activate it.
    if ($this->entity->isNew()) {
    $actions['submit']['#value'] = $this->t('Save and switch');
    $actions['submit']['#submit'] = ['::submitForm', '::save', '::activate'];
    $actions['save'] = [
    '#type' => 'submit',
    '#value' => $this->t('Save'),
    '#submit' => ['::submitForm', '::save'],
    ];
    }
    return $actions;
    }
    /**
    * {@inheritdoc}
    */
    ......@@ -134,11 +130,11 @@ public function save(array $form, FormStateInterface $form_state) {
    if ($status == SAVED_UPDATED) {
    $logger->notice('@type: updated %info.', $context);
    $this->messenger->addMessage($this->t('Workspace %info has been updated.', $info));
    $this->messenger()->addMessage($this->t('Workspace %info has been updated.', $info));
    }
    else {
    $logger->notice('@type: added %info.', $context);
    $this->messenger->addMessage($this->t('Workspace %info has been created.', $info));
    $this->messenger()->addMessage($this->t('Workspace %info has been created.', $info));
    }
    if ($workspace->id()) {
    ......@@ -150,9 +146,24 @@ public function save(array $form, FormStateInterface $form_state) {
    $form_state->setRedirectUrl($redirect);
    }
    else {
    $this->messenger->addError($this->t('The workspace could not be saved.'));
    $this->messenger()->addError($this->t('The workspace could not be saved.'));
    $form_state->setRebuild();
    }
    }
    /**
    * Form submission handler for the 'submit' action.
    *
    * @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 activate(array $form, FormStateInterface $form_state): void {
    $this->workspaceManager->setActiveWorkspace($this->entity);
    $this->messenger()->addMessage($this->t('%label is now the active workspace.', [
    '%label' => $this->entity->label(),
    ]));
    }
    }
    ......@@ -47,8 +47,7 @@ public function testBypassOwnWorkspace() {
    // Login as a limited-access user and create a workspace.
    $this->drupalLogin($coach);
    $bears = $this->createWorkspaceThroughUi('Bears', 'bears');
    $this->switchToWorkspace($bears);
    $bears = $this->createAndActivateWorkspaceThroughUi('Bears', 'bears');
    // Now create a node in the Bears workspace, as the owner of that workspace.
    $coach_bears_node = $this->createNodeThroughUi('Ditka Bears node', 'test');
    ......
    ......@@ -50,9 +50,7 @@ protected function setUp(): void {
    * Tests switching workspace via the switcher block and admin page.
    */
    public function testSwitchingWorkspaces() {
    $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
    $this->switchToWorkspace($vultures);
    $this->createAndActivateWorkspaceThroughUi('Vultures', 'vultures');
    $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
    $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');
    ......
    ......@@ -80,15 +80,16 @@ protected function setUp(): void {
    */
    public function testSpecialCharacters() {
    $this->drupalLogin($this->editor1);
    $page = $this->getSession()->getPage();
    // Test a valid workspace name.
    $this->createWorkspaceThroughUi('Workspace 1', 'a0_$()+-/');
    $this->createAndActivateWorkspaceThroughUi('Workspace 1', 'workspace_1');
    $this->assertSession()->elementTextContains('css', '.workspaces-toolbar-tab', 'Workspace 1');
    // Test and invalid workspace name.
    $this->drupalGet('/admin/config/workflow/workspaces/add');
    $this->assertSession()->statusCodeEquals(200);
    $page = $this->getSession()->getPage();
    $page->fillField('label', 'workspace2');
    $page->fillField('id', 'A!"£%^&*{}#~@?');
    $page->findButton('Save')->click();
    ......@@ -251,11 +252,10 @@ public function testDeleteWorkspaceWithExistingContent() {
    // Login and create a workspace.
    $this->drupalLogin($this->rootUser);
    $may_4 = $this->createWorkspaceThroughUi('May 4', 'may_4');
    $this->switchToWorkspace($may_4);
    $this->createAndActivateWorkspaceThroughUi('May 4', 'may_4');
    // Create a node in the workspace.
    $node = $this->createNodeThroughUi('A mayfly flies / In May or June', 'test');
    $this->createNodeThroughUi('A mayfly flies / In May or June', 'test');
    // Delete the workspace.
    $this->drupalGet('/admin/config/workflow/workspaces/manage/may_4/delete');
    ......
    ......@@ -46,6 +46,32 @@ protected function getOneEntityByLabel($type, $label) {
    return $entity;
    }
    /**
    * Creates and activates a new Workspace through the UI.
    *
    * @param string $label
    * The label of the workspace to create.
    * @param string $id
    * The ID of the workspace to create.
    * @param string $parent
    * (optional) The ID of the parent workspace. Defaults to '_none'.
    *
    * @return \Drupal\workspaces\WorkspaceInterface
    * The workspace that was just created.
    */
    protected function createAndActivateWorkspaceThroughUi(string $label, string $id, string $parent = '_none'): WorkspaceInterface {
    $this->drupalGet('/admin/config/workflow/workspaces/add');
    $this->submitForm([
    'id' => $id,
    'label' => $label,
    'parent' => $parent,
    ], 'Save and switch');
    $this->getSession()->getPage()->hasContent("$label ($id)");
    return Workspace::load($id);
    }
    /**
    * Creates a new Workspace through the UI.
    *
    ......
    • catch @catch

      mentioned in commit a20e795b

      ·

      mentioned in commit a20e795b

      Toggle commit list
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment