diff -u b/core/modules/media/config/schema/media.schema.yml b/core/modules/media/config/schema/media.schema.yml --- b/core/modules/media/config/schema/media.schema.yml +++ b/core/modules/media/config/schema/media.schema.yml @@ -40,10 +40,6 @@ type: media.source.field_aware label: '"File" media source configuration' -media.source.image: - type: media.source.field_aware - label: '"Image" media source configuration' - action.configuration.media_delete_action: type: action_configuration_default label: 'Delete media configuration' @@ -52,6 +48,10 @@ 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: reverted: --- b/core/modules/media/config/schema/media.schema.yml.orig +++ /dev/null @@ -1,68 +0,0 @@ -media.settings: - type: config_object - label: 'Media settings' - mapping: - icon_base_uri: - type: string - label: 'Full URI to a folder where the media icons will be installed' - -media.type.*: - type: config_entity - label: 'Media type' - mapping: - id: - type: string - label: 'Machine name' - label: - type: label - label: 'Name' - description: - type: text - label: 'Description' - source: - type: string - label: 'Source' - source_configuration: - type: media.source.[%parent.source] - queue_thumbnail_downloads: - type: boolean - label: 'Whether the thumbnail downloads should be queued' - new_revision: - type: boolean - label: 'Whether a new revision should be created by default' - field_map: - type: sequence - label: 'Field map' - sequence: - type: string - -action.configuration.media_delete_action: - type: action_configuration_default - label: 'Delete media configuration' - -action.configuration.media_save_action: - type: action_configuration_default - label: 'Save media configuration' - -action.configuration.media_publish_action: - type: action_configuration_default - label: 'Publish media configuration' - -action.configuration.media_unpublish_action: - type: action_configuration_default - label: 'Unpublish media configuration' - -field.formatter.settings.media_thumbnail: - type: field.formatter.settings.image - label: 'Media thumbnail field display format settings' - -media.source.*: - type: mapping - label: 'Media source settings' - -media.source.field_aware: - type: mapping - mapping: - source_field: - type: string - label: 'Source field' reverted: --- b/core/modules/media/src/MediaSourceInterface.php +++ a/core/modules/media/src/MediaSourceInterface.php @@ -82,16 +82,6 @@ const METADATA_ATTRIBUTE_SIZE = 'size'; /** - * Key for width metadata attribute. - */ - const METADATA_ATTRIBUTE_WIDTH = 'width'; - - /** - * Key for height metadata attribute. - */ - const METADATA_ATTRIBUTE_HEIGHT = 'height'; - - /** * Gets a list of metadata attributes provided by this plugin. * * Most media sources have associated metadata, describing attributes diff -u b/core/modules/media/src/Plugin/media/Source/Image.php b/core/modules/media/src/Plugin/media/Source/Image.php --- b/core/modules/media/src/Plugin/media/Source/Image.php +++ b/core/modules/media/src/Plugin/media/Source/Image.php @@ -11,7 +11,6 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Image\ImageFactory; use Drupal\media\MediaInterface; -use Drupal\media\MediaSourceInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -30,6 +29,20 @@ class Image extends File { /** + * Key for width metadata attribute. + * + * @var int + */ + const METADATA_ATTRIBUTE_WIDTH = 'width'; + + /** + * Key for height metadata attribute. + * + * @var int + */ + const METADATA_ATTRIBUTE_HEIGHT = 'height'; + + /** * The image factory service. * * @var \Drupal\Core\Image\ImageFactory @@ -103,8 +116,8 @@ $attributes = parent::getMetadataAttributes(); $attributes += [ - MediaSourceInterface::METADATA_ATTRIBUTE_WIDTH => $this->t('Width'), - MediaSourceInterface::METADATA_ATTRIBUTE_HEIGHT => $this->t('Height'), + static::METADATA_ATTRIBUTE_WIDTH => $this->t('Width'), + static::METADATA_ATTRIBUTE_HEIGHT => $this->t('Height'), ]; if ($this->canReadExifData()) { @@ -128,18 +141,18 @@ // Get the file, image and EXIF data. /** @var \Drupal\file\FileInterface $file */ $file = $media->get($this->configuration['source_field'])->entity; - // If field media type is not required. + // If the source field is not required, it may be empty. if (!$file) { - return NULL; + return parent::getMetadata($media, $name); } + $uri = $file->getFileUri(); $image = $this->imageFactory->get($uri); - switch ($name) { - case MediaSourceInterface::METADATA_ATTRIBUTE_WIDTH: + case static::METADATA_ATTRIBUTE_WIDTH: return $image->getWidth() ?: NULL; - case MediaSourceInterface::METADATA_ATTRIBUTE_HEIGHT: + case static::METADATA_ATTRIBUTE_HEIGHT: return $image->getHeight() ?: NULL; case 'thumbnail_uri':