Skip to content
Snippets Groups Projects
Commit a20e795b 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

(cherry picked from commit d84f2c9d)
parent c84ae09d
No related branches found
No related tags found
32 merge requests!12684Issue #3220784,!12537Add ViewsConfigUpdater deprecation support for default_argument_skip_url,!12523Issue #3493858 by vidorado, xavier.masson, smustgrave: Extend ViewsBlockBase...,!122353526426-warning-for-missing,!12212Issue #3445525 by alexpott, japerry, catch, mglaman, longwave: Add BC layer...,!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #124073 passed
Pipeline: drupal

#124099

    Pipeline: drupal

    #124092

      Pipeline: drupal

      #124084

        +1
        ...@@ -2,14 +2,11 @@ ...@@ -2,14 +2,11 @@
        namespace Drupal\workspaces\Form; namespace Drupal\workspaces\Form;
        use Drupal\Component\Datetime\TimeInterface;
        use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\ContentEntityForm;
        use Drupal\Core\Entity\EntityConstraintViolationListInterface; use Drupal\Core\Entity\EntityConstraintViolationListInterface;
        use Drupal\Core\Entity\EntityRepositoryInterface;
        use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
        use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
        use Drupal\Core\Messenger\MessengerInterface;
        use Drupal\Core\Url; use Drupal\Core\Url;
        use Drupal\workspaces\WorkspaceManagerInterface;
        use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
        /** /**
        ...@@ -25,39 +22,17 @@ class WorkspaceForm extends ContentEntityForm implements WorkspaceFormInterface ...@@ -25,39 +22,17 @@ class WorkspaceForm extends ContentEntityForm implements WorkspaceFormInterface
        protected $entity; protected $entity;
        /** /**
        * The messenger service. * The workspace manager.
        *
        * @var \Drupal\Core\Messenger\MessengerInterface
        */ */
        protected $messenger; protected WorkspaceManagerInterface $workspaceManager;
        /**
        * 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;
        }
        /** /**
        * {@inheritdoc} * {@inheritdoc}
        */ */
        public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
        return new static( $instance = parent::create($container);
        $container->get('entity.repository'), $instance->workspaceManager = $container->get('workspaces.manager');
        $container->get('messenger'), return $instance;
        $container->get('entity_type.bundle.info'),
        $container->get('datetime.time')
        );
        } }
        /** /**
        ...@@ -120,6 +95,27 @@ protected function flagViolations(EntityConstraintViolationListInterface $violat ...@@ -120,6 +95,27 @@ protected function flagViolations(EntityConstraintViolationListInterface $violat
        parent::flagViolations($violations, $form, $form_state); 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} * {@inheritdoc}
        */ */
        ...@@ -134,11 +130,11 @@ public function save(array $form, FormStateInterface $form_state) { ...@@ -134,11 +130,11 @@ public function save(array $form, FormStateInterface $form_state) {
        if ($status == SAVED_UPDATED) { if ($status == SAVED_UPDATED) {
        $logger->notice('@type: updated %info.', $context); $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 { else {
        $logger->notice('@type: added %info.', $context); $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()) { if ($workspace->id()) {
        ...@@ -150,9 +146,24 @@ public function save(array $form, FormStateInterface $form_state) { ...@@ -150,9 +146,24 @@ public function save(array $form, FormStateInterface $form_state) {
        $form_state->setRedirectUrl($redirect); $form_state->setRedirectUrl($redirect);
        } }
        else { 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_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() { ...@@ -47,8 +47,7 @@ public function testBypassOwnWorkspace() {
        // Login as a limited-access user and create a workspace. // Login as a limited-access user and create a workspace.
        $this->drupalLogin($coach); $this->drupalLogin($coach);
        $bears = $this->createWorkspaceThroughUi('Bears', 'bears'); $bears = $this->createAndActivateWorkspaceThroughUi('Bears', 'bears');
        $this->switchToWorkspace($bears);
        // Now create a node in the Bears workspace, as the owner of that workspace. // Now create a node in the Bears workspace, as the owner of that workspace.
        $coach_bears_node = $this->createNodeThroughUi('Ditka Bears node', 'test'); $coach_bears_node = $this->createNodeThroughUi('Ditka Bears node', 'test');
        ......
        ...@@ -50,9 +50,7 @@ protected function setUp(): void { ...@@ -50,9 +50,7 @@ protected function setUp(): void {
        * Tests switching workspace via the switcher block and admin page. * Tests switching workspace via the switcher block and admin page.
        */ */
        public function testSwitchingWorkspaces() { public function testSwitchingWorkspaces() {
        $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures'); $this->createAndActivateWorkspaceThroughUi('Vultures', 'vultures');
        $this->switchToWorkspace($vultures);
        $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity'); $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
        $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate'); $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');
        ......
        ...@@ -80,15 +80,16 @@ protected function setUp(): void { ...@@ -80,15 +80,16 @@ protected function setUp(): void {
        */ */
        public function testSpecialCharacters() { public function testSpecialCharacters() {
        $this->drupalLogin($this->editor1); $this->drupalLogin($this->editor1);
        $page = $this->getSession()->getPage();
        // Test a valid workspace name. // 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. // Test and invalid workspace name.
        $this->drupalGet('/admin/config/workflow/workspaces/add'); $this->drupalGet('/admin/config/workflow/workspaces/add');
        $this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
        $page = $this->getSession()->getPage();
        $page->fillField('label', 'workspace2'); $page->fillField('label', 'workspace2');
        $page->fillField('id', 'A!"£%^&*{}#~@?'); $page->fillField('id', 'A!"£%^&*{}#~@?');
        $page->findButton('Save')->click(); $page->findButton('Save')->click();
        ...@@ -251,11 +252,10 @@ public function testDeleteWorkspaceWithExistingContent() { ...@@ -251,11 +252,10 @@ public function testDeleteWorkspaceWithExistingContent() {
        // Login and create a workspace. // Login and create a workspace.
        $this->drupalLogin($this->rootUser); $this->drupalLogin($this->rootUser);
        $may_4 = $this->createWorkspaceThroughUi('May 4', 'may_4'); $this->createAndActivateWorkspaceThroughUi('May 4', 'may_4');
        $this->switchToWorkspace($may_4);
        // Create a node in the workspace. // 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. // Delete the workspace.
        $this->drupalGet('/admin/config/workflow/workspaces/manage/may_4/delete'); $this->drupalGet('/admin/config/workflow/workspaces/manage/may_4/delete');
        ......
        ...@@ -46,6 +46,32 @@ protected function getOneEntityByLabel($type, $label) { ...@@ -46,6 +46,32 @@ protected function getOneEntityByLabel($type, $label) {
        return $entity; 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. * Creates a new Workspace through the UI.
        * *
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment