Issue #3066802 by oknate, anmolgoyal74, phenaproxima, Wim Leers, webchick, seanB, effulgentsia, catch, Nick_vh, marcoscano: Ensure that embedded image media items do not display at unreasonable sizes by default
parent
5fabcffb44
commit
97811f7568
|
|
@ -9,10 +9,13 @@ use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
|
|||
use Drupal\Core\File\Exception\FileException;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\media\Entity\MediaType;
|
||||
use Drupal\media\MediaTypeInterface;
|
||||
use Drupal\media\Plugin\media\Source\OEmbedInterface;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\image\Plugin\Field\FieldType\ImageItem;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
|
|
@ -118,6 +121,55 @@ function media_requirements($phase) {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
// When a new media type with an image source is created we're configuring
|
||||
// the default entity view display using the 'large' image style.
|
||||
// Unfortunately, if a site builder has deleted the 'large' image style,
|
||||
// we need some other image style to use, but at this point, we can't
|
||||
// really know the site builder's intentions. So rather than do something
|
||||
// surprising, we're leaving the embedded media without an image style and
|
||||
// adding a warning that the site builder might want to add an image style.
|
||||
// @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay
|
||||
$module_handler = \Drupal::service('module_handler');
|
||||
foreach (MediaType::loadMultiple() as $type) {
|
||||
// Load the default display.
|
||||
$display = \Drupal::service('entity_display.repository')
|
||||
->getViewDisplay('media', $type->id());
|
||||
|
||||
$source_field_definition = $type->getSource()->getSourceFieldDefinition($type);
|
||||
if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$component = $display->getComponent($source_field_definition->getName());
|
||||
if (empty($component) || $component['type'] !== 'image' || !empty($component['settings']['image_style'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$action_item = '';
|
||||
if ($module_handler->moduleExists('field_ui') && \Drupal::currentUser()->hasPermission('administer media display')) {
|
||||
$url = Url::fromRoute('entity.entity_view_display.media.default', [
|
||||
'media_type' => $type->id(),
|
||||
])->toString();
|
||||
$action_item = new TranslatableMarkup('If you would like to change this, <a href=":display">add an image style to the %field_name field</a>.',
|
||||
[
|
||||
'%field_name' => $source_field_definition->label(),
|
||||
':display' => $url,
|
||||
]);
|
||||
}
|
||||
$requirements['media_default_image_style_' . $type->id()] = [
|
||||
'title' => t('Media'),
|
||||
'description' => new TranslatableMarkup('The default display for the %type media type is not currently using an image style on the %field_name field. Not using an image style can lead to much larger file downloads. @action_item',
|
||||
[
|
||||
'%field_name' => $source_field_definition->label(),
|
||||
'@action_item' => $action_item,
|
||||
'%type' => $type->label(),
|
||||
]
|
||||
),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\media\Plugin\media\Source\Image;
|
||||
use Drupal\media\Plugin\media\Source\OEmbedInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -508,3 +509,33 @@ function media_field_widget_form_alter(&$element, FormStateInterface $form_state
|
|||
$element['#attributes']['data-media-embed-host-entity-langcode'] = $context['items']->getLangcode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function media_form_media_type_add_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
|
||||
$form['actions']['submit']['#submit'][] = '_media_type_add_form_submit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for media_type_add_form.
|
||||
*/
|
||||
function _media_type_add_form_submit(array &$form, FormStateInterface $form_state) {
|
||||
$type = $form_state->getFormObject()->getEntity();
|
||||
|
||||
if (!is_a($type->getSource(), Image::class, TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the default entity view display.
|
||||
$display = \Drupal::service('entity_display.repository')
|
||||
->getViewDisplay('media', $type->id());
|
||||
|
||||
// Remove all default components.
|
||||
foreach (array_keys($display->getComponents()) as $name) {
|
||||
$display->removeComponent($name);
|
||||
}
|
||||
$type->getSource()->prepareViewDisplay($type, $display);
|
||||
|
||||
$display->save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* description = @Translation("Embeds media items using a custom tag, <code><drupal-media></code>. If used in conjunction with the 'Align/Caption' filters, make sure this filter is configured to run after them."),
|
||||
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
|
||||
* settings = {
|
||||
* "default_view_mode" = "full",
|
||||
* "default_view_mode" = "default",
|
||||
* },
|
||||
* weight = 100,
|
||||
* )
|
||||
|
|
@ -266,12 +266,15 @@ class MediaEmbed extends FilterBase implements ContainerFactoryPluginInterface,
|
|||
$this->applyPerEmbedMediaOverrides($node, $media);
|
||||
}
|
||||
|
||||
$view_mode = $this->entityRepository->loadEntityByConfigTarget('entity_view_mode', "media.$view_mode_id");
|
||||
if (!$view_mode) {
|
||||
$this->loggerFactory->get('media')->error('During rendering of embedded media: the view mode "@view-mode-id" does not exist.', ['@view-mode-id' => $view_mode_id]);
|
||||
$view_mode = NULL;
|
||||
if ($view_mode_id !== EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE) {
|
||||
$view_mode = $this->entityRepository->loadEntityByConfigTarget('entity_view_mode', "media.$view_mode_id");
|
||||
if (!$view_mode) {
|
||||
$this->loggerFactory->get('media')->error('During rendering of embedded media: the view mode "@view-mode-id" does not exist.', ['@view-mode-id' => $view_mode_id]);
|
||||
}
|
||||
}
|
||||
|
||||
$build = $media && $view_mode
|
||||
$build = $media && ($view_mode || $view_mode_id === EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE)
|
||||
? $this->renderMedia($media, $view_mode_id, $langcode)
|
||||
: $this->renderMissingMediaIndicator();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\media\Plugin\media\Source;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
|
|
@ -161,4 +162,25 @@ class Image extends File {
|
|||
return $field->set('settings', $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
|
||||
parent::prepareViewDisplay($type, $display);
|
||||
|
||||
// Use the `large` image style and do not link the image to anything.
|
||||
// This will prevent the out-of-the-box configuration from outputting very
|
||||
// large raw images. If the `large` image style has been deleted, do not
|
||||
// set an image style.
|
||||
$field_name = $this->getSourceFieldDefinition($type)->getName();
|
||||
$component = $display->getComponent($field_name);
|
||||
$component['label'] = 'visually_hidden';
|
||||
$component['settings']['image_link'] = '';
|
||||
$component['settings']['image_style'] = '';
|
||||
if ($this->entityTypeManager->getStorage('image_style')->load('large')) {
|
||||
$component['settings']['image_style'] = 'large';
|
||||
}
|
||||
$display->setComponent($field_name, $component);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,10 +101,14 @@ class MediaDisplayTest extends MediaJavascriptTestBase {
|
|||
// Assert the image is present inside the media element.
|
||||
$media_item = $assert_session->elementExists('css', '.media--type-image > div');
|
||||
$assert_session->elementExists('css', 'img', $media_item);
|
||||
// Assert that the image src is the original image and not an image style.
|
||||
// Assert that the image src uses the large image style, the label is
|
||||
// visually hidden, and there is no link to the image file.
|
||||
$media_image = $assert_session->elementExists('css', '.media--type-image img');
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/example_1.jpeg')));
|
||||
$this->assertSame($expected_image_src, $media_image->getAttribute('src'));
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/example_1.jpeg')));
|
||||
$this->assertContains($expected_image_src, $media_image->getAttribute('src'));
|
||||
$field = $assert_session->elementExists('css', '.field--name-field-media-image');
|
||||
$assert_session->elementExists('css', '.field__label.visually-hidden', $field);
|
||||
$assert_session->elementNotExists('css', 'a', $field);
|
||||
|
||||
$test_filename = $this->randomMachineName() . '.txt';
|
||||
$test_filepath = 'public://' . $test_filename;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,14 @@
|
|||
|
||||
namespace Drupal\Tests\media\FunctionalJavascript;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\media\Entity\Media;
|
||||
use Drupal\media\Entity\MediaType;
|
||||
use Drupal\media\Plugin\media\Source\Image;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the image media source.
|
||||
|
|
@ -57,16 +63,119 @@ class MediaSourceImageTest extends MediaSourceTestBase {
|
|||
// Get the media entity view URL from the creation message.
|
||||
$this->drupalGet($this->assertLinkToCreatedMedia());
|
||||
|
||||
// Make sure the thumbnail is displayed from uploaded image.
|
||||
$assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', 'example_1.jpeg');
|
||||
// Ensure the thumbnail has the correct alt attribute.
|
||||
$assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'alt', 'Image Alt Text 1');
|
||||
// Assert the image element is present inside the media element and that its
|
||||
// src attribute uses the large image style, the label is visually hidden,
|
||||
// and there is no link to the image file.
|
||||
$image_element = $assert_session->elementExists('css', '.field--name-field-media-image img');
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/example_1.jpeg')));
|
||||
$this->assertContains($expected_image_src, $image_element->getAttribute('src'));
|
||||
$field = $assert_session->elementExists('css', '.field--name-field-media-image');
|
||||
$assert_session->elementExists('css', '.field__label.visually-hidden', $field);
|
||||
$assert_session->elementNotExists('css', 'a', $field);
|
||||
|
||||
// Ensure the image has the correct alt attribute.
|
||||
$this->assertSame('Image Alt Text 1', $image_element->getAttribute('alt'));
|
||||
|
||||
// Load the media and check that all fields are properly populated.
|
||||
$media = Media::load(1);
|
||||
$this->assertSame('example_1.jpeg', $media->getName());
|
||||
$this->assertSame('200', $media->get('field_string_width')->value);
|
||||
$this->assertSame('89', $media->get('field_string_height')->value);
|
||||
|
||||
// Tests the warning when the default display's image style is missing.
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'administer site configuration',
|
||||
'access media overview',
|
||||
'administer media',
|
||||
'administer media types',
|
||||
'administer media display',
|
||||
'view media',
|
||||
// We need 'access content' for system.machine_name_transliterate.
|
||||
'access content',
|
||||
]));
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
$assert_session = $this->assertSession();
|
||||
// If for some reason a site builder deletes the 'large' image style, do
|
||||
// not add an image style to the new entity view display's image field.
|
||||
// Instead, add a warning on the 'Status report' page.
|
||||
ImageStyle::load('large')->delete();
|
||||
$this->drupalGet('admin/structure/media/add');
|
||||
$page->fillField('label', 'Madame Bonacieux');
|
||||
$this->assertNotEmpty($assert_session->waitForText('Machine name: madame_bonacieux'));
|
||||
$page->selectFieldOption('source', 'image');
|
||||
// Wait for the form to complete with AJAX.
|
||||
$this->assertNotEmpty($assert_session->waitForText('Field mapping'));
|
||||
$page->pressButton('Save');
|
||||
$this->assertViewDisplayConfigured('madame_bonacieux');
|
||||
|
||||
// Create user without the 'administer media display' permission.
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'administer site configuration',
|
||||
'access media overview',
|
||||
'administer media',
|
||||
'administer media types',
|
||||
'view media',
|
||||
// We need 'access content' for system.machine_name_transliterate.
|
||||
'access content',
|
||||
]));
|
||||
// Test that hook_requirements adds warning about the lack of an image
|
||||
// style.
|
||||
$this->drupalGet('/admin/reports/status');
|
||||
// The image style warning should not include an action link when the
|
||||
// current user lacks the permission 'administer media display'.
|
||||
$assert_session->pageTextContains('The default display for the Madame Bonacieux media type is not currently using an image style on the Image field. Not using an image style can lead to much larger file downloads.');
|
||||
$assert_session->linkNotExists('add an image style to the Image field');
|
||||
$assert_session->linkByHrefNotExists('/admin/structure/media/manage/madame_bonacieux/display');
|
||||
|
||||
// The image style warning should include an action link when the current
|
||||
// user has the permission 'administer media display'.
|
||||
Role::load(RoleInterface::AUTHENTICATED_ID)
|
||||
->grantPermission('administer media display')
|
||||
->save();
|
||||
$this->drupalGet('/admin/reports/status');
|
||||
$assert_session->pageTextContains('The default display for the Madame Bonacieux media type is not currently using an image style on the Image field. Not using an image style can lead to much larger file downloads. If you would like to change this, add an image style to the Image field.');
|
||||
$assert_session->linkExists('add an image style to the Image field');
|
||||
$assert_session->linkByHrefExists('/admin/structure/media/manage/madame_bonacieux/display');
|
||||
|
||||
// The image style warning should not include an action link when the
|
||||
// Field UI module is uninstalled.
|
||||
$this->container->get('module_installer')->uninstall(['field_ui']);
|
||||
$this->drupalGet('/admin/reports/status');
|
||||
$assert_session->pageTextContains('The default display for the Madame Bonacieux media type is not currently using an image style on the Image field. Not using an image style can lead to much larger file downloads.');
|
||||
$assert_session->linkNotExists('add an image style to the Image field');
|
||||
$assert_session->linkByHrefNotExists('/admin/structure/media/manage/madame_bonacieux/display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the proper entity view display components for a media type.
|
||||
*
|
||||
* @param string $media_type_id
|
||||
* The media type ID.
|
||||
*/
|
||||
protected function assertViewDisplayConfigured($media_type_id) {
|
||||
$assert_session = $this->assertSession();
|
||||
$type = MediaType::load($media_type_id);
|
||||
$display = EntityViewDisplay::load('media.' . $media_type_id . '.' . EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE);
|
||||
$this->assertInstanceOf(EntityViewDisplay::class, $display);
|
||||
$source_field_definition = $type->getSource()->getSourceFieldDefinition($type);
|
||||
$component = $display->getComponent($source_field_definition->getName());
|
||||
$this->assertSame('visually_hidden', $component['label']);
|
||||
if (ImageStyle::load('large')) {
|
||||
$this->assertSame('large', $component['settings']['image_style']);
|
||||
}
|
||||
else {
|
||||
$this->assertEmpty($component['settings']['image_style']);
|
||||
}
|
||||
$this->assertEmpty($component['settings']['image_link']);
|
||||
|
||||
// Since components that aren't explicitly hidden can show up on the
|
||||
// display edit form, check that only the image field appears enabled on
|
||||
// the display edit form.
|
||||
$this->drupalGet('/admin/structure/media/manage/' . $media_type_id . '/display');
|
||||
// Assert that only the source field is enabled.
|
||||
$assert_session->elementExists('css', 'input[name="' . $source_field_definition->getName() . '_settings_edit"]');
|
||||
$assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,10 +230,13 @@ class MediaStandardProfileTest extends MediaJavascriptTestBase {
|
|||
$assert_session->elementsCount('css', 'article.media--type-image > *', 1);
|
||||
|
||||
// Assert the image element is present inside the media element and that its
|
||||
// src attribute matches the image.
|
||||
// src attribute uses the large image style, the label is visually hidden,
|
||||
// and there is no link to the image file.
|
||||
$image_element = $assert_session->elementExists('css', 'article.media--type-image img');
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/' . $image_media_name)));
|
||||
$this->assertSame($expected_image_src, $image_element->getAttribute('src'));
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/' . $image_media_name)));
|
||||
$this->assertContains($expected_image_src, $image_element->getAttribute('src'));
|
||||
$assert_session->elementExists('css', '.field--name-field-media-image .field__label.visually-hidden');
|
||||
$assert_session->elementNotExists('css', '.field--name-field-media-image a');
|
||||
|
||||
// Assert the media name is updated through the field mapping when changing
|
||||
// the source field.
|
||||
|
|
@ -259,10 +262,13 @@ class MediaStandardProfileTest extends MediaJavascriptTestBase {
|
|||
$assert_session->elementsCount('css', 'article.media--type-image > *', 1);
|
||||
|
||||
// Assert the image element is present inside the media element and that its
|
||||
// src attribute matches the updated image.
|
||||
// src attribute uses the large image style, the label is visually hidden,
|
||||
// and there is no link to the image file.
|
||||
$image_element = $assert_session->elementExists('css', 'article.media--type-image img');
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/' . $image_media_name_updated)));
|
||||
$this->assertSame($expected_image_src, $image_element->getAttribute('src'));
|
||||
$expected_image_src = file_url_transform_relative(file_create_url(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/' . $image_media_name_updated)));
|
||||
$this->assertContains($expected_image_src, $image_element->getAttribute('src'));
|
||||
$assert_session->elementExists('css', '.field--name-field-media-image .field__label.visually-hidden');
|
||||
$assert_session->elementNotExists('css', '.field--name-field-media-image a');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\media\Kernel;
|
|||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +45,7 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
* Data provider for testBasics().
|
||||
*/
|
||||
public function providerTestBasics() {
|
||||
$expected_cacheability_full = (new CacheableMetadata())
|
||||
$default_cacheability = (new CacheableMetadata())
|
||||
->setCacheTags([
|
||||
'_media_test_filter_access:media:1',
|
||||
'_media_test_filter_access:user:2',
|
||||
|
|
@ -58,14 +59,14 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
->setCacheMaxAge(Cache::PERMANENT);
|
||||
|
||||
return [
|
||||
'data-entity-uuid only ⇒ default view mode "full" used' => [
|
||||
'data-entity-uuid only ⇒ default view mode used' => [
|
||||
[
|
||||
'data-entity-type' => 'media',
|
||||
'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
|
||||
],
|
||||
'full',
|
||||
EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE,
|
||||
[],
|
||||
$expected_cacheability_full,
|
||||
$default_cacheability,
|
||||
],
|
||||
'data-entity-uuid + data-view-mode=full ⇒ specified view mode used' => [
|
||||
[
|
||||
|
|
@ -75,7 +76,17 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
],
|
||||
'full',
|
||||
[],
|
||||
$expected_cacheability_full,
|
||||
$default_cacheability,
|
||||
],
|
||||
'data-entity-uuid + data-view-mode=default ⇒ specified view mode used' => [
|
||||
[
|
||||
'data-entity-type' => 'media',
|
||||
'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
|
||||
'data-view-mode' => EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE,
|
||||
],
|
||||
EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE,
|
||||
[],
|
||||
$default_cacheability,
|
||||
],
|
||||
'data-entity-uuid + data-view-mode=foobar ⇒ specified view mode used' => [
|
||||
[
|
||||
|
|
@ -103,12 +114,12 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
'data-entity-type' => 'media',
|
||||
'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
|
||||
],
|
||||
'full',
|
||||
EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE,
|
||||
[
|
||||
'data-foo' => 'bar',
|
||||
'foo' => 'bar',
|
||||
],
|
||||
$expected_cacheability_full,
|
||||
$default_cacheability,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
@ -138,7 +149,7 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
$this->assertEmpty($this->getRawContent());
|
||||
}
|
||||
else {
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="full"]'));
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="default"]'));
|
||||
}
|
||||
|
||||
$this->assertSame($expected_cacheability->getCacheTags(), $result->getCacheTags());
|
||||
|
|
@ -375,7 +386,7 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
// Render and verify the presence of the embedded entity 20 times.
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$this->applyFilter($text);
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="full"]'));
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="default"]'));
|
||||
}
|
||||
|
||||
// Render a 21st time, this is exceeding the recursion limit. The entity
|
||||
|
|
@ -399,7 +410,7 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase {
|
|||
$result = $this->processText($content, 'en', $filter_ids);
|
||||
$this->setRawContent($result->getProcessedText());
|
||||
$this->assertCount($expected_verification_success ? 1 : 0, $this->cssSelect($verification_selector));
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="full"]'));
|
||||
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="default"]'));
|
||||
$this->assertSame([
|
||||
'_media_test_filter_access:media:1',
|
||||
'_media_test_filter_access:user:2',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ status: true
|
|||
dependencies:
|
||||
config:
|
||||
- field.field.media.image.field_media_image
|
||||
- image.style.large
|
||||
- media.type.image
|
||||
module:
|
||||
- image
|
||||
|
|
@ -14,8 +15,8 @@ content:
|
|||
field_media_image:
|
||||
label: visually_hidden
|
||||
settings:
|
||||
image_style: ''
|
||||
image_link: file
|
||||
image_style: 'large'
|
||||
image_link: ''
|
||||
third_party_settings: { }
|
||||
type: image
|
||||
weight: 1
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ status: true
|
|||
dependencies:
|
||||
config:
|
||||
- field.field.media.image.field_media_image
|
||||
- image.style.medium
|
||||
- image.style.large
|
||||
- media.type.image
|
||||
module:
|
||||
- image
|
||||
|
|
@ -15,8 +15,8 @@ content:
|
|||
field_media_image:
|
||||
label: visually_hidden
|
||||
settings:
|
||||
image_style: ''
|
||||
image_link: file
|
||||
image_style: 'large'
|
||||
image_link: ''
|
||||
third_party_settings: { }
|
||||
type: image
|
||||
weight: 1
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\standard\Functional;
|
|||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\media\Entity\MediaType;
|
||||
use Drupal\media\Plugin\media\Source\Image;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
use Drupal\Core\Url;
|
||||
|
|
@ -232,6 +233,7 @@ class StandardTest extends BrowserTestBase {
|
|||
'label' => 'Admin media',
|
||||
]);
|
||||
$role->grantPermission('administer media');
|
||||
$role->grantPermission('administer media display');
|
||||
$role->save();
|
||||
$this->adminUser->addRole($role->id());
|
||||
$this->adminUser->save();
|
||||
|
|
@ -256,6 +258,17 @@ class StandardTest extends BrowserTestBase {
|
|||
$date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml();
|
||||
$published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml();
|
||||
$this->assertTrue(strpos($form_html, $published_checkbox) > strpos($form_html, $date_field));
|
||||
if (is_a($media_type->getSource(), Image::class, TRUE)) {
|
||||
// Assert the default entity view display is configured with an image
|
||||
// style.
|
||||
$this->drupalGet('/admin/structure/media/manage/' . $media_type->id() . '/display');
|
||||
$assert_session->fieldValueEquals('fields[field_media_image][type]', 'image');
|
||||
$assert_session->elementTextContains('css', 'tr[data-drupal-selector="edit-fields-field-media-image"]', 'Image style: Large (480×480)');
|
||||
// By default for media types with an image source, only the image
|
||||
// component should be enabled.
|
||||
$assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue