Loading core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php +10 −3 Original line number Diff line number Diff line Loading @@ -103,11 +103,18 @@ public function mediaEntityMetadata(Request $request) { $image_field = $this->getMediaImageSourceFieldName($media); $response = []; $response['type'] = $media->bundle(); // If this uses the image media source and the "alt" field is enabled, // expose additional metadata. // @see \Drupal\media\Plugin\media\Source\Image // @see core/modules/ckeditor5/js/ckeditor5_plugins/drupalMedia/src/mediaimagetextalternative/mediaimagetextalternativeui.js if ($image_field) { $settings = $media->{$image_field}->getItemDefinition()->getSettings(); if (!empty($settings['alt_field'])) { $response['imageSourceMetadata'] = [ 'alt' => $this->entityRepository->getTranslationFromContext($media)->{$image_field}->alt, ]; } } // Note that we intentionally do not use: // - \Drupal\Core\Cache\CacheableResponse because caching it on the server Loading core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\ckeditor5\Plugin\Editor\CKEditor5; use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\filter\Entity\FilterFormat; use Drupal\language\Entity\ConfigurableLanguage; Loading Loading @@ -230,6 +231,16 @@ public function testApi() { $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'image', 'imageSourceMetadata' => ['alt' => '']]), $this->getSession()->getPage()->getContent()); // Test that setting the media image field to not display alt field also // omits it from the API (which will in turn instruct the CKE5 plugin to not // show it). FieldConfig::loadByName('media', 'image', 'field_media_image') ->setSetting('alt_field', FALSE) ->save(); $this->drupalGet($path, ['query' => ['uuid' => $uuid, 'token' => $token]]); $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'image']), $this->getSession()->getPage()->getContent()); $this->drupalGet($path, ['query' => ['uuid' => $this->mediaFile->uuid(), 'token' => $token]]); $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'file']), $this->getSession()->getPage()->getContent()); Loading core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php +28 −4 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\Core\Database\Database; use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\filter\Entity\FilterFormat; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; Loading Loading @@ -627,11 +628,34 @@ public function testEditableCaption() { } /** * Tests the EditorMediaDialog's form elements' #access logic. * Tests that the image media source's alt_field being disabled is respected. * * @see \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::testApi() */ public function testDialogAccess() { // @todo Port in https://www.drupal.org/project/ckeditor5/issues/3245720 $this->markTestSkipped('Blocked on https://www.drupal.org/project/ckeditor5/issues/3245720.'); public function testAltDisabled(): void { // Disable the alt field for image media. FieldConfig::loadByName('media', 'image', 'field_media_image') ->setSetting('alt_field', FALSE) ->save(); $assert_session = $this->assertSession(); $this->drupalGet($this->host->toUrl('edit-form')); $this->waitForEditor(); // Wait for the media preview to load. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img')); // Test that by default no alt attribute is present on the drupal-media // element. $this->assertSourceAttributeSame('alt', NULL); // Test that the preview shows the alt value from the media field's // alt text. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img[alt*="default alt"]')); // Test that clicking the media widget triggers a CKEditor balloon panel // with a single button to override the alt text. $this->click('.ck-widget.drupal-media'); $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]'); // Assert that no "Override media image alternative text" button is visible. $override_alt_button = $this->getBalloonButton('Override media image alternative text'); $this->assertFalse($override_alt_button->isVisible()); } /** Loading Loading
core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php +10 −3 Original line number Diff line number Diff line Loading @@ -103,11 +103,18 @@ public function mediaEntityMetadata(Request $request) { $image_field = $this->getMediaImageSourceFieldName($media); $response = []; $response['type'] = $media->bundle(); // If this uses the image media source and the "alt" field is enabled, // expose additional metadata. // @see \Drupal\media\Plugin\media\Source\Image // @see core/modules/ckeditor5/js/ckeditor5_plugins/drupalMedia/src/mediaimagetextalternative/mediaimagetextalternativeui.js if ($image_field) { $settings = $media->{$image_field}->getItemDefinition()->getSettings(); if (!empty($settings['alt_field'])) { $response['imageSourceMetadata'] = [ 'alt' => $this->entityRepository->getTranslationFromContext($media)->{$image_field}->alt, ]; } } // Note that we intentionally do not use: // - \Drupal\Core\Cache\CacheableResponse because caching it on the server Loading
core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\ckeditor5\Plugin\Editor\CKEditor5; use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\filter\Entity\FilterFormat; use Drupal\language\Entity\ConfigurableLanguage; Loading Loading @@ -230,6 +231,16 @@ public function testApi() { $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'image', 'imageSourceMetadata' => ['alt' => '']]), $this->getSession()->getPage()->getContent()); // Test that setting the media image field to not display alt field also // omits it from the API (which will in turn instruct the CKE5 plugin to not // show it). FieldConfig::loadByName('media', 'image', 'field_media_image') ->setSetting('alt_field', FALSE) ->save(); $this->drupalGet($path, ['query' => ['uuid' => $uuid, 'token' => $token]]); $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'image']), $this->getSession()->getPage()->getContent()); $this->drupalGet($path, ['query' => ['uuid' => $this->mediaFile->uuid(), 'token' => $token]]); $this->assertSession()->statusCodeEquals(200); $this->assertSame(json_encode(['type' => 'file']), $this->getSession()->getPage()->getContent()); Loading
core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php +28 −4 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\Core\Database\Database; use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\filter\Entity\FilterFormat; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; Loading Loading @@ -627,11 +628,34 @@ public function testEditableCaption() { } /** * Tests the EditorMediaDialog's form elements' #access logic. * Tests that the image media source's alt_field being disabled is respected. * * @see \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::testApi() */ public function testDialogAccess() { // @todo Port in https://www.drupal.org/project/ckeditor5/issues/3245720 $this->markTestSkipped('Blocked on https://www.drupal.org/project/ckeditor5/issues/3245720.'); public function testAltDisabled(): void { // Disable the alt field for image media. FieldConfig::loadByName('media', 'image', 'field_media_image') ->setSetting('alt_field', FALSE) ->save(); $assert_session = $this->assertSession(); $this->drupalGet($this->host->toUrl('edit-form')); $this->waitForEditor(); // Wait for the media preview to load. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img')); // Test that by default no alt attribute is present on the drupal-media // element. $this->assertSourceAttributeSame('alt', NULL); // Test that the preview shows the alt value from the media field's // alt text. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img[alt*="default alt"]')); // Test that clicking the media widget triggers a CKEditor balloon panel // with a single button to override the alt text. $this->click('.ck-widget.drupal-media'); $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]'); // Assert that no "Override media image alternative text" button is visible. $override_alt_button = $this->getBalloonButton('Override media image alternative text'); $this->assertFalse($override_alt_button->isVisible()); } /** Loading