diff --git a/core/modules/media/config/install/core.entity_form_display.media.image.default.yml b/core/modules/media/config/install/core.entity_form_display.media.image.default.yml new file mode 100644 index 0000000000..7806770ef9 --- /dev/null +++ b/core/modules/media/config/install/core.entity_form_display.media.image.default.yml @@ -0,0 +1,46 @@ +langcode: en +status: true +dependencies: + config: + - field.field.media.image.field_media_image + - image.style.thumbnail + - media.type.image + module: + - image +id: media.image.default +targetEntityType: media +bundle: image +mode: default +content: + created: + type: datetime_timestamp + weight: 10 + region: content + settings: { } + third_party_settings: { } + field_media_image: + settings: + progress_indicator: throbber + preview_image_style: thumbnail + third_party_settings: { } + type: image_image + weight: 26 + region: content + name: + type: string_textfield + weight: -5 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + uid: + type: entity_reference_autocomplete + weight: 5 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + region: content + third_party_settings: { } +hidden: { } diff --git a/core/modules/media/config/install/core.entity_view_display.media.image.default.yml b/core/modules/media/config/install/core.entity_view_display.media.image.default.yml new file mode 100644 index 0000000000..e541d7f784 --- /dev/null +++ b/core/modules/media/config/install/core.entity_view_display.media.image.default.yml @@ -0,0 +1,51 @@ +langcode: en +status: true +dependencies: + config: + - field.field.media.image.field_media_image + - image.style.thumbnail + - media.type.image + module: + - image + - user +id: media.image.default +targetEntityType: media +bundle: image +mode: default +content: + created: + label: hidden + type: timestamp + weight: 0 + region: content + settings: + date_format: medium + custom_date_format: '' + timezone: '' + third_party_settings: { } + field_media_image: + label: above + settings: + image_style: '' + image_link: '' + third_party_settings: { } + type: image + weight: 6 + region: content + thumbnail: + type: image + weight: 5 + label: hidden + settings: + image_style: thumbnail + image_link: '' + region: content + third_party_settings: { } + uid: + label: hidden + type: author + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: { } diff --git a/core/modules/media/config/install/field.field.media.image.field_media_image.yml b/core/modules/media/config/install/field.field.media.image.field_media_image.yml new file mode 100644 index 0000000000..f6a62cc595 --- /dev/null +++ b/core/modules/media/config/install/field.field.media.image.field_media_image.yml @@ -0,0 +1,40 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.media.field_media_image + - media.type.image + enforced: + module: + - media + module: + - image +id: media.image.field_media_image +field_name: field_media_image +entity_type: media +bundle: image +label: Image +description: '' +required: true +translatable: true +default_value: { } +default_value_callback: '' +settings: + alt_field: true + alt_field_required: true + title_field: false + title_field_required: false + max_resolution: '' + min_resolution: '' + default_image: + uuid: null + alt: '' + title: '' + width: null + height: null + file_directory: '[date:custom:Y]-[date:custom:m]' + file_extensions: 'png gif jpg jpeg' + max_filesize: '' + handler: 'default:file' + handler_settings: { } +field_type: image diff --git a/core/modules/media/config/install/field.storage.media.field_media_file.yml b/core/modules/media/config/install/field.storage.media.field_media_file.yml index c251e11666..344abd1761 100644 --- a/core/modules/media/config/install/field.storage.media.field_media_file.yml +++ b/core/modules/media/config/install/field.storage.media.field_media_file.yml @@ -20,6 +20,6 @@ module: file locked: true cardinality: 1 translatable: true -indexes: { } +indexes: { } persist_with_no_fields: false custom_storage: false diff --git a/core/modules/media/config/install/field.storage.media.field_media_file.yml b/core/modules/media/config/install/field.storage.media.field_media_image.yml similarity index 62% copy from core/modules/media/config/install/field.storage.media.field_media_file.yml copy to core/modules/media/config/install/field.storage.media.field_media_image.yml index c251e11666..155db1173e 100644 --- a/core/modules/media/config/install/field.storage.media.field_media_file.yml +++ b/core/modules/media/config/install/field.storage.media.field_media_image.yml @@ -6,20 +6,27 @@ dependencies: - media module: - file + - image - media -id: media.field_media_file -field_name: field_media_file +id: media.field_media_image +field_name: field_media_image entity_type: media -type: file +type: image settings: - uri_scheme: public + default_image: + uuid: null + alt: '' + title: '' + width: null + height: null target_type: file display_field: false display_default: false -module: file + uri_scheme: public +module: image locked: true cardinality: 1 translatable: true -indexes: { } +indexes: { } persist_with_no_fields: false custom_storage: false diff --git a/core/modules/media/config/install/media.type.file.yml b/core/modules/media/config/install/media.type.file.yml index af0abc2716..a716fc1852 100644 --- a/core/modules/media/config/install/media.type.file.yml +++ b/core/modules/media/config/install/media.type.file.yml @@ -9,4 +9,4 @@ queue_thumbnail_downloads: false new_revision: true source_configuration: source_field: field_media_file -field_map: { } +field_map: { } diff --git a/core/modules/media/config/install/media.type.image.yml b/core/modules/media/config/install/media.type.image.yml new file mode 100644 index 0000000000..9527f625fc --- /dev/null +++ b/core/modules/media/config/install/media.type.image.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: { } +id: image +label: Image +description: "Use local images for reusable media." +source: image +queue_thumbnail_downloads: false +new_revision: true +source_configuration: + source_field: field_media_image +field_map: { } diff --git a/core/modules/media/config/schema/media.schema.yml b/core/modules/media/config/schema/media.schema.yml index 69740f75ee..dad518985a 100644 --- a/core/modules/media/config/schema/media.schema.yml +++ b/core/modules/media/config/schema/media.schema.yml @@ -48,6 +48,10 @@ media.source.file: type: media.source.field_aware label: '"File" media source configuration' +media.source.image: + type: media.source.field_aware + label: '"Image" media source configuration' + media.source.field_aware: type: mapping mapping: diff --git a/core/modules/media/images/icons/no-thumbnail.png b/core/modules/media/images/icons/no-thumbnail.png new file mode 100644 index 0000000000..10851aae57 --- /dev/null +++ b/core/modules/media/images/icons/no-thumbnail.png @@ -0,0 +1,4 @@ +PNG + + IHDRYIDATx@ߠp`A +\@R 9@ףw^bXA  4hРA 4hРA 4hРA 4hРA :?V~u}imageFactory = $image_factory; + $this->fileSystem = $file_system; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager'), + $container->get('entity_field.manager'), + $container->get('plugin.manager.field.field_type'), + $container->get('config.factory'), + $container->get('image.factory'), + $container->get('file_system') + ); + } + + /** + * {@inheritdoc} + */ + public function getMetadataAttributes() { + $attributes = parent::getMetadataAttributes(); + + $attributes += [ + static::METADATA_ATTRIBUTE_WIDTH => $this->t('Width'), + static::METADATA_ATTRIBUTE_HEIGHT => $this->t('Height'), + ]; + + return $attributes; + } + + /** + * {@inheritdoc} + */ + public function getMetadata(MediaInterface $media, $name) { + // Get the file and image data. + /** @var \Drupal\file\FileInterface $file */ + $file = $media->get($this->configuration['source_field'])->entity; + // If the source field is not required, it may be empty. + if (!$file) { + return parent::getMetadata($media, $name); + } + + $uri = $file->getFileUri(); + $image = $this->imageFactory->get($uri); + switch ($name) { + case static::METADATA_ATTRIBUTE_WIDTH: + return $image->getWidth() ?: NULL; + + case static::METADATA_ATTRIBUTE_HEIGHT: + return $image->getHeight() ?: NULL; + + case 'thumbnail_uri': + return $uri; + } + + return parent::getMetadata($media, $name); + } + + /** + * {@inheritdoc} + */ + public function createSourceField(MediaTypeInterface $type) { + /** @var \Drupal\field\FieldConfigInterface $field */ + $field = parent::createSourceField($type); + + // Reset the field to its default settings so that we don't inherit the + // settings from the parent class' source field. + $settings = $this->fieldTypeManager->getDefaultFieldSettings($field->getType()); + + return $field->set('settings', $settings); + } + +} diff --git a/core/modules/media/tests/fixtures/example_1.jpeg b/core/modules/media/tests/fixtures/example_1.jpeg new file mode 100644 index 0000000000..e04cde60ca --- /dev/null +++ b/core/modules/media/tests/fixtures/example_1.jpeg @@ -0,0 +1,51 @@ +JFIFHHExifMM*bx(i%Drupal EXIF Camera 1HH'0210 +01002014:08:28 06:52:007NPEh4` Əhttp://ns.adobe.com/xap/1.0/ + + + + + Drupal EXIF Camera + 72 + 72 + Inch + Centered + Exif Version 2.1 + FlashPix Version 1.0 + Uncalibrated + N + 52, 30, 32.751 + E + 13, 22, 25.5432 + + + + + +C + + +    C   Y HNƋ`:Q&Y9nZl(-p㓟{'h\R@o3uv'N%Wi}cʭ0E-%+[}[/OI^fdp,Ć^_?}:ΞQ]gYh2Z]ՋEgDhf )ɋK0q,LGduV٭N#kOHW+Tס_D;|t!ΪNrvb=%qkMtQ#}vw]vHxzysl_i-vtv¯\.Ыj]]$:o,o>ma_[ +ȔJYԷ+ 콟C!yWK?܋2jU潲˅ˤQX' 6@03PH}jr5fKl\m5 q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KąSTNRFR< m³&gNUybDֳP5ӝB149Nc]: 1_^FVĦtʭRU鹣z4S5}IB +pUȃǖbxGύӒys޼o +1cXaYvlrŇQY<{SI@7Kछ+8s484;E0]+Yy]3پXkСWl"oPd̴sʅԈjE]Rա ÏlFX-k e^bNed&81p,$ RhFdIl~.i7u1$\,Hi&#^ C9+?QX0bRG=*a9CJbiٟ} D#}U+|Ten9.Rol1b528$nMgšɗEtJ0E)u~+SL&!1AQaq @0P?;Y(>*Tʯ $s pF-JJ$4 Z`ZiHM|AD yb0[f)ۿG]W&c^gXTRW @HD)QiϑP1 +0FTv3^1*x4}!meKTUniK GQ&6L~]-d(%᎐qS!rU^qtQv P9@khKKwfD5j;{ޏMGuChV@1Qކa#6 r^~FFǒhbE;K5?YcB2G&ƃgWgPlRassertSession(); + + /** @var \Drupal\field\FieldConfigInterface $field */ + // Disable the alt text field, because this is not a JavaScript test and + // the alt text field will therefore not appear without a full page refresh. + $field = FieldConfig::load('media.image.field_media_image'); + $settings = $field->getSettings(); + $settings['alt_field'] = FALSE; + $settings['alt_field_required'] = FALSE; + $field->set('settings', $settings); + $field->save(); + + // Create a media item. + $this->drupalGet('/media/add/image'); + $page = $this->getSession()->getPage(); + $page->fillField('Name', 'Foobar'); + $page->attachFileToField('Image', \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); + $page->pressButton('Save and publish'); + $assert->addressMatches('/^\/media\/[0-9]+$/'); + + // The media item was just created, so it should only have one revision. + $media = $this->container + ->get('entity_type.manager') + ->getStorage('media') + ->load(1); + $this->assertRevisionCount($media, 1); + + // If we edit the item, we should get a new revision. + $this->drupalGet('/media/1/edit'); + $assert->checkboxChecked('Create new revision'); + $page = $this->getSession()->getPage(); + $page->fillField('Name', 'Foobaz'); + $page->pressButton('Save and keep published'); + $this->assertRevisionCount($media, 2); + } + + /** * Asserts that an entity has a certain number of revisions. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php index e37b850c75..8f3f67506a 100644 --- a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php +++ b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php @@ -33,6 +33,7 @@ protected function setUp() { // We need to test without any default configuration in place. // @TODO: Remove this when https://www.drupal.org/node/2883813 lands. MediaType::load('file')->delete(); + MediaType::load('image')->delete(); } /** diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php new file mode 100644 index 0000000000..0505d3bb11 --- /dev/null +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php @@ -0,0 +1,79 @@ +delete(); + MediaType::load('image')->delete(); + } + + /** + * Tests the image media source. + */ + public function testMediaImageSource() { + $media_type_id = 'test_media_image_type'; + $source_field_id = 'field_media_image'; + $provided_fields = [ + Image::METADATA_ATTRIBUTE_WIDTH, + Image::METADATA_ATTRIBUTE_HEIGHT, + ]; + + $session = $this->getSession(); + $page = $session->getPage(); + $assert_session = $this->assertSession(); + + $this->doTestCreateMediaType($media_type_id, 'image', $provided_fields); + + // Create custom fields for the media type to store metadata attributes. + $fields = [ + 'field_string_width' => 'string', + 'field_string_height' => 'string', + ]; + $this->createMediaTypeFields($fields, $media_type_id); + + // Hide the name field widget to test default name generation. + $this->hideMediaTypeFieldWidget('name', $media_type_id); + + $this->drupalGet("admin/structure/media/manage/{$media_type_id}"); + $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_WIDTH . "]", 'field_string_width'); + $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_HEIGHT . "]", 'field_string_height'); + $page->pressButton('Save'); + + // Create a media item. + $this->drupalGet("media/add/{$media_type_id}"); + $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); + $assert_session->assertWaitOnAjaxRequest(); + $page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1'); + $page->pressButton('Save and publish'); + + $assert_session->addressEquals('media/1'); + + // Make sure the thumbnail is displayed from uploaded image. + $assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', 'example_1.jpeg'); + + // Load the media and check that all fields are properly populated. + $media = Media::load(1); + $this->assertEquals('example_1.jpeg', $media->label()); + $this->assertEquals('200', $media->get('field_string_width')->value); + $this->assertEquals('89', $media->get('field_string_height')->value); + } + +} diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php index 5af6d5c143..24cd134266 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php @@ -37,10 +37,22 @@ protected function createMediaTypeField($field_name, $field_type, $media_type_id // Make the field widget visible in the form display. $component = \Drupal::service('plugin.manager.field.widget') ->prepareConfiguration($field_type, []); - /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */ + + // @todo Replace entity_get_form_display() when #2367933 is done. + // https://www.drupal.org/node/2872159. $entity_form_display = entity_get_form_display('media', $media_type_id, 'default'); $entity_form_display->setComponent($field_name, $component) ->save(); + + // Use the default formatter and settings. + $component = \Drupal::service('plugin.manager.field.formatter') + ->prepareConfiguration($field_type, []); + + // @todo Replace entity_get_display() when #2367933 is done. + // https://www.drupal.org/node/2872159. + $entity_display = entity_get_display('media', $media_type_id, 'default'); + $entity_display->setComponent($field_name, $component) + ->save(); } /** diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php index bb49fefc56..b150f894da 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php @@ -42,6 +42,7 @@ protected function setUp() { // We need to test without any default configuration in place. // @TODO: Remove this as part of https://www.drupal.org/node/2883813. MediaType::load('file')->delete(); + MediaType::load('image')->delete(); } /** diff --git a/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php b/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php index 9ad6916a38..d716e15b40 100644 --- a/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php +++ b/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php @@ -20,6 +20,7 @@ protected function setUp() { // We need to test without any default configuration in place. // @TODO: Remove this as part of https://www.drupal.org/node/2883813. MediaType::load('file')->delete(); + MediaType::load('image')->delete(); } /**