Loading core/modules/workspaces/src/EntityOperations.php +2 −2 Changes for core/modules/workspaces/src/EntityOperations.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, $f // be a pending one. $active_workspace = $this->workspaceManager->getActiveWorkspace(); if (!$active_workspace->isDefaultWorkspace()) { $form['#entity_builders'][] = [$this, 'entityFormEntityBuild']; $form['#entity_builders'][] = [get_called_class(), 'entityFormEntityBuild']; } /** @var \Drupal\workspaces\WorkspaceAssociationStorageInterface $workspace_association_storage */ Loading @@ -340,7 +340,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, $f /** * Entity builder that marks all supported entities as pending revisions. */ public function entityFormEntityBuild($entity_type_id, RevisionableInterface $entity, &$form, FormStateInterface &$form_state) { public static function entityFormEntityBuild($entity_type_id, RevisionableInterface $entity, &$form, FormStateInterface &$form_state) { // Set the non-default revision flag so that validation constraints are also // aware that a pending revision is about to be created. $entity->isDefaultRevision(FALSE); Loading core/modules/workspaces/src/FormOperations.php +4 −6 Changes for core/modules/workspaces/src/FormOperations.php: 4 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\views\Form\ViewsExposedForm; use Drupal\workspaces\Form\WorkspaceFormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -17,8 +17,6 @@ */ class FormOperations implements ContainerInjectionInterface { use StringTranslationTrait; /** * The workspace manager service. * Loading Loading @@ -104,16 +102,16 @@ protected function addWorkspaceValidation(array &$element) { } if (isset($element['#validate'])) { $element['#validate'][] = [$this, 'validateDefaultWorkspace']; $element['#validate'][] = [get_called_class(), 'validateDefaultWorkspace']; } } /** * Validation handler which sets a validation error for all unsupported forms. */ public function validateDefaultWorkspace(array &$form, FormStateInterface $form_state) { public static function validateDefaultWorkspace(array &$form, FormStateInterface $form_state) { if ($form_state->get('workspace_safe') !== TRUE) { $form_state->setError($form, $this->t('This form can only be submitted in the default workspace.')); $form_state->setError($form, new TranslatableMarkup('This form can only be submitted in the default workspace.')); } } Loading core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +33 −0 Changes for core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php: 33 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,10 +3,12 @@ namespace Drupal\Tests\workspaces\Kernel; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Form\FormState; use Drupal\entity_test\Entity\EntityTestMulRev; use Drupal\entity_test\Entity\EntityTestMulRevPub; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Form\SiteInformationForm; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; Loading Loading @@ -718,4 +720,35 @@ protected function flattenExpectedValues(array $expected, $entity_type_id) { return $flattened; } /** * Tests that entity forms can be stored in the form cache. */ public function testFormCacheForEntityForms() { $this->initializeWorkspacesModule(); $this->switchToWorkspace('stage'); $form_builder = $this->container->get('form_builder'); $form = $this->entityTypeManager->getFormObject('entity_test_mulrevpub', 'default'); $form->setEntity(EntityTestMulRevPub::create([])); $form_state = new FormState(); $built_form = $form_builder->buildForm($form, $form_state); $form_builder->setCache($built_form['#build_id'], $built_form, $form_state); } /** * Tests that non-entity forms can be stored in the form cache. */ public function testFormCacheForRegularForms() { $this->initializeWorkspacesModule(); $this->switchToWorkspace('stage'); $form_builder = $this->container->get('form_builder'); $form_state = new FormState(); $built_form = $form_builder->getForm(SiteInformationForm::class, $form_state); $form_builder->setCache($built_form['#build_id'], $built_form, $form_state); } } Loading
core/modules/workspaces/src/EntityOperations.php +2 −2 Changes for core/modules/workspaces/src/EntityOperations.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, $f // be a pending one. $active_workspace = $this->workspaceManager->getActiveWorkspace(); if (!$active_workspace->isDefaultWorkspace()) { $form['#entity_builders'][] = [$this, 'entityFormEntityBuild']; $form['#entity_builders'][] = [get_called_class(), 'entityFormEntityBuild']; } /** @var \Drupal\workspaces\WorkspaceAssociationStorageInterface $workspace_association_storage */ Loading @@ -340,7 +340,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, $f /** * Entity builder that marks all supported entities as pending revisions. */ public function entityFormEntityBuild($entity_type_id, RevisionableInterface $entity, &$form, FormStateInterface &$form_state) { public static function entityFormEntityBuild($entity_type_id, RevisionableInterface $entity, &$form, FormStateInterface &$form_state) { // Set the non-default revision flag so that validation constraints are also // aware that a pending revision is about to be created. $entity->isDefaultRevision(FALSE); Loading
core/modules/workspaces/src/FormOperations.php +4 −6 Changes for core/modules/workspaces/src/FormOperations.php: 4 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\views\Form\ViewsExposedForm; use Drupal\workspaces\Form\WorkspaceFormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -17,8 +17,6 @@ */ class FormOperations implements ContainerInjectionInterface { use StringTranslationTrait; /** * The workspace manager service. * Loading Loading @@ -104,16 +102,16 @@ protected function addWorkspaceValidation(array &$element) { } if (isset($element['#validate'])) { $element['#validate'][] = [$this, 'validateDefaultWorkspace']; $element['#validate'][] = [get_called_class(), 'validateDefaultWorkspace']; } } /** * Validation handler which sets a validation error for all unsupported forms. */ public function validateDefaultWorkspace(array &$form, FormStateInterface $form_state) { public static function validateDefaultWorkspace(array &$form, FormStateInterface $form_state) { if ($form_state->get('workspace_safe') !== TRUE) { $form_state->setError($form, $this->t('This form can only be submitted in the default workspace.')); $form_state->setError($form, new TranslatableMarkup('This form can only be submitted in the default workspace.')); } } Loading
core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +33 −0 Changes for core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php: 33 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,10 +3,12 @@ namespace Drupal\Tests\workspaces\Kernel; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Form\FormState; use Drupal\entity_test\Entity\EntityTestMulRev; use Drupal\entity_test\Entity\EntityTestMulRevPub; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Form\SiteInformationForm; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; Loading Loading @@ -718,4 +720,35 @@ protected function flattenExpectedValues(array $expected, $entity_type_id) { return $flattened; } /** * Tests that entity forms can be stored in the form cache. */ public function testFormCacheForEntityForms() { $this->initializeWorkspacesModule(); $this->switchToWorkspace('stage'); $form_builder = $this->container->get('form_builder'); $form = $this->entityTypeManager->getFormObject('entity_test_mulrevpub', 'default'); $form->setEntity(EntityTestMulRevPub::create([])); $form_state = new FormState(); $built_form = $form_builder->buildForm($form, $form_state); $form_builder->setCache($built_form['#build_id'], $built_form, $form_state); } /** * Tests that non-entity forms can be stored in the form cache. */ public function testFormCacheForRegularForms() { $this->initializeWorkspacesModule(); $this->switchToWorkspace('stage'); $form_builder = $this->container->get('form_builder'); $form_state = new FormState(); $built_form = $form_builder->getForm(SiteInformationForm::class, $form_state); $form_builder->setCache($built_form['#build_id'], $built_form, $form_state); } }