Loading core/modules/media_library/src/Form/AddFormBase.php +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use Drupal\Core\Form\BaseFormIdInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\WorkspaceSafeFormInterface; use Drupal\Core\Render\Element; use Drupal\Core\Security\TrustedCallbackInterface; use Drupal\Core\Url; Loading @@ -27,7 +28,7 @@ /** * Provides a base class for creating media items from within the media library. */ abstract class AddFormBase extends FormBase implements BaseFormIdInterface, TrustedCallbackInterface { abstract class AddFormBase extends FormBase implements BaseFormIdInterface, TrustedCallbackInterface, WorkspaceSafeFormInterface { /** * The entity type manager. Loading core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php +2 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Ajax\MessageCommand; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\WorkspaceSafeFormInterface; use Drupal\Core\Url; use Drupal\media_library\MediaLibraryState; use Drupal\views\Attribute\ViewsField; Loading @@ -22,7 +23,7 @@ * Plugin classes are internal. */ #[ViewsField("media_library_select_form")] class MediaLibrarySelectForm extends FieldPluginBase { class MediaLibrarySelectForm extends FieldPluginBase implements WorkspaceSafeFormInterface { /** * {@inheritdoc} Loading core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesMediaLibraryIntegrationTest.php 0 → 100644 +67 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\workspaces\FunctionalJavascript; use Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest; use Drupal\user\UserInterface; use Drupal\workspaces\Entity\Workspace; /** * Tests the Media library entity reference widget in a workspace. * * @group workspaces */ class WorkspacesMediaLibraryIntegrationTest extends EntityReferenceWidgetTest { /** * {@inheritdoc} */ protected static $modules = [ 'workspaces', ]; /** * An array of test methods that are not relevant for workspaces. */ const SKIP_METHODS = [ // This test does not assert anything that can be workspace-specific. 'testFocusNotAppliedWithoutSelectionChange', // This test does not assert anything that can be workspace-specific. 'testRequiredMediaField', // This test tries to edit an entity in Live after it has been edited in a // workspace, which is not currently possible. 'testWidgetPreview', ]; /** * {@inheritdoc} */ public function setUp(): void { if (in_array($this->name(), static::SKIP_METHODS, TRUE)) { $this->markTestSkipped('Irrelevant for this test'); } parent::setUp(); // Ensure that all the test methods are executed in the context of a // workspace. $stage = Workspace::load('stage'); \Drupal::service('workspaces.manager')->setActiveWorkspace($stage); } /** * {@inheritdoc} */ protected function drupalCreateUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []): UserInterface|false { // Ensure that users and roles are managed outside a workspace context. return \Drupal::service('workspaces.manager')->executeOutsideWorkspace(function () use ($permissions, $name, $admin, $values) { $permissions = array_merge($permissions, [ 'view any workspace', ]); return parent::drupalCreateUser($permissions, $name, $admin, $values); }); } } Loading
core/modules/media_library/src/Form/AddFormBase.php +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use Drupal\Core\Form\BaseFormIdInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\WorkspaceSafeFormInterface; use Drupal\Core\Render\Element; use Drupal\Core\Security\TrustedCallbackInterface; use Drupal\Core\Url; Loading @@ -27,7 +28,7 @@ /** * Provides a base class for creating media items from within the media library. */ abstract class AddFormBase extends FormBase implements BaseFormIdInterface, TrustedCallbackInterface { abstract class AddFormBase extends FormBase implements BaseFormIdInterface, TrustedCallbackInterface, WorkspaceSafeFormInterface { /** * The entity type manager. Loading
core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php +2 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Ajax\MessageCommand; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\WorkspaceSafeFormInterface; use Drupal\Core\Url; use Drupal\media_library\MediaLibraryState; use Drupal\views\Attribute\ViewsField; Loading @@ -22,7 +23,7 @@ * Plugin classes are internal. */ #[ViewsField("media_library_select_form")] class MediaLibrarySelectForm extends FieldPluginBase { class MediaLibrarySelectForm extends FieldPluginBase implements WorkspaceSafeFormInterface { /** * {@inheritdoc} Loading
core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesMediaLibraryIntegrationTest.php 0 → 100644 +67 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\workspaces\FunctionalJavascript; use Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest; use Drupal\user\UserInterface; use Drupal\workspaces\Entity\Workspace; /** * Tests the Media library entity reference widget in a workspace. * * @group workspaces */ class WorkspacesMediaLibraryIntegrationTest extends EntityReferenceWidgetTest { /** * {@inheritdoc} */ protected static $modules = [ 'workspaces', ]; /** * An array of test methods that are not relevant for workspaces. */ const SKIP_METHODS = [ // This test does not assert anything that can be workspace-specific. 'testFocusNotAppliedWithoutSelectionChange', // This test does not assert anything that can be workspace-specific. 'testRequiredMediaField', // This test tries to edit an entity in Live after it has been edited in a // workspace, which is not currently possible. 'testWidgetPreview', ]; /** * {@inheritdoc} */ public function setUp(): void { if (in_array($this->name(), static::SKIP_METHODS, TRUE)) { $this->markTestSkipped('Irrelevant for this test'); } parent::setUp(); // Ensure that all the test methods are executed in the context of a // workspace. $stage = Workspace::load('stage'); \Drupal::service('workspaces.manager')->setActiveWorkspace($stage); } /** * {@inheritdoc} */ protected function drupalCreateUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []): UserInterface|false { // Ensure that users and roles are managed outside a workspace context. return \Drupal::service('workspaces.manager')->executeOutsideWorkspace(function () use ($permissions, $name, $admin, $values) { $permissions = array_merge($permissions, [ 'view any workspace', ]); return parent::drupalCreateUser($permissions, $name, $admin, $values); }); } }