diff --git a/core/modules/media/config/schema/media.schema.yml b/core/modules/media/config/schema/media.schema.yml
index 363f61b47a..a63aa5c35d 100644
--- a/core/modules/media/config/schema/media.schema.yml
+++ b/core/modules/media/config/schema/media.schema.yml
@@ -42,7 +42,7 @@ media.source.file:
media.source.image:
type: media.source.field_aware
- label: 'Image source configuration'
+ label: '"Image" media source configuration'
action.configuration.media_delete_action:
type: action_configuration_default
diff --git a/core/modules/media/src/MediaSourceInterface.php b/core/modules/media/src/MediaSourceInterface.php
index 4c3b783222..c25fd49e08 100644
--- a/core/modules/media/src/MediaSourceInterface.php
+++ b/core/modules/media/src/MediaSourceInterface.php
@@ -82,6 +82,16 @@
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 --git a/core/modules/media/src/Plugin/media/Source/Image.php b/core/modules/media/src/Plugin/media/Source/Image.php
index 9717a503d5..18967283b0 100644
--- a/core/modules/media/src/Plugin/media/Source/Image.php
+++ b/core/modules/media/src/Plugin/media/Source/Image.php
@@ -11,6 +11,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageFactory;
use Drupal\media\MediaInterface;
+use Drupal\media\MediaSourceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -21,7 +22,7 @@
* @MediaSource(
* id = "image",
* label = @Translation("Image"),
- * description = @Translation("Allows local images to be used as media."),
+ * description = @Translation("Use local images for reusable media."),
* allowed_field_types = {"image"},
* default_thumbnail_filename = "no-thumbnail.png"
* )
@@ -102,8 +103,8 @@ public function getMetadataAttributes() {
$attributes = parent::getMetadataAttributes();
$attributes += [
- 'width' => $this->t('Width'),
- 'height' => $this->t('Height'),
+ MediaSourceInterface::METADATA_ATTRIBUTE_WIDTH => $this->t('Width'),
+ MediaSourceInterface::METADATA_ATTRIBUTE_HEIGHT => $this->t('Height'),
];
if ($this->canReadExifData()) {
@@ -127,18 +128,18 @@ public function getMetadata(MediaInterface $media, $name) {
// 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 (!$file) {
return NULL;
}
$uri = $file->getFileUri();
$image = $this->imageFactory->get($uri);
- // Return the field.
switch ($name) {
- case 'width':
+ case MediaSourceInterface::METADATA_ATTRIBUTE_WIDTH:
return $image->getWidth() ?: NULL;
- case 'height':
+ case MediaSourceInterface::METADATA_ATTRIBUTE_HEIGHT:
return $image->getHeight() ?: NULL;
case 'thumbnail_uri':
@@ -178,10 +179,9 @@ public function getMetadata(MediaInterface $media, $name) {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
- // Show message if it's not possible to read EXIF data.
if (!$this->canReadExifData()) {
$form['no_exif_data_reader'] = [
- '#markup' => $this->t('Unable to read EXIF data for Image. In order to provide EXIF data reading functionality please take a look at PHP documentation of exif_read_data function.'),
+ '#markup' => $this->t('Unable to read EXIF data for images. In order to provide EXIF data reading functionality please take a look at PHP documentation of the exif_read_data function.'),
];
}
@@ -202,12 +202,12 @@ protected function canReadExifData() {
* Gets EXIF field value.
*
* @param string $uri
- * The uri for the file that we are getting the EXIF.
+ * The URI for the file that we are getting the EXIF for.
* @param string $field
- * The name of the EXIF field.
+ * The name of the requested EXIF field.
*
* @return string|bool
- * The value for the requested field or FALSE if is not set.
+ * The value for the requested field or FALSE if it is not set.
*/
protected function getExifField($uri, $field) {
if (empty($this->exif)) {
@@ -221,10 +221,10 @@ protected function getExifField($uri, $field) {
* Reads EXIF.
*
* @param string $uri
- * The URI for the file that we are getting the EXIF.
+ * The URI for the file that we are getting the EXIF field value.
*
* @return array|bool
- * An associative array where the indexes are header names and values are
+ * An associative array where the keys are header names and values are
* the values associated with those headers. We return FALSE if the data
* can't be read.
*/
diff --git a/core/modules/media/tests/fixtures/exif_example.jpeg b/core/modules/media/tests/fixtures/exif_example_1.jpeg
similarity index 95%
rename from core/modules/media/tests/fixtures/exif_example.jpeg
rename to core/modules/media/tests/fixtures/exif_example_1.jpeg
index 2cba9b9b9c..ac79b36804 100644
--- a/core/modules/media/tests/fixtures/exif_example.jpeg
+++ b/core/modules/media/tests/fixtures/exif_example_1.jpeg
@@ -1,4 +1,4 @@
- JFIF H H Exif MM * b v ~( i % Drupal EXIF Camera H H 0210 0100 N E 4 `
Ə http://ns.adobe.com/xap/1.0/
+ JFIF H H Exif MM * b x ( i % Drupal EXIF Camera 1 H H 0210 0100 N E 4 `
Ə http://ns.adobe.com/xap/1.0/
diff --git a/core/modules/media/tests/fixtures/exif_example_2.jpeg b/core/modules/media/tests/fixtures/exif_example_2.jpeg
new file mode 100644
index 0000000000..0cbd028f76
--- /dev/null
+++ b/core/modules/media/tests/fixtures/exif_example_2.jpeg
@@ -0,0 +1,50 @@
+ JFIF H H Exif MM * b x ( i % Drupal EXIF Camera 2 H H 0210 0100 N E 4 `
Ə 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 H N Ƌ`:Q&Y 9nZl(-p㓟{'h \R@o3uv'N %Wi}c ʭ0 E-% +[}[ /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?܋2 j U潲˅ˤQX ' 6@03P H}jr5fKl\m5
qYqhci8Ǻ7}Fzetc4
+B/,(
%UR:sZy<ٖ.~ɟR`=
^%#?1ZwFh?;3Z#.K֓8#s;qWB/(]iCI
=*@/.&{')MtZQ5Xn5P𛇤JfKʻs}%eg"d!?iqIpkůhU衈>=քN6:~J)anjZYp{YgPMR\Q;5vA*>2m YC[~(SHl"ٵk֦%r- ?@Mi7D$lSC`Yt4t77: