diff --git a/core/modules/media/media.module b/core/modules/media/media.module index fa02caf938..97f0ae846c 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -114,7 +114,7 @@ function media_field_widget_string_textfield_form_alter(array &$element, FormSta if (!empty($element['value'])) { /** @var \Drupal\media\MediaInterface $media */ $media = $context['items']->getEntity(); - if (!($media instanceof MediaInterface)) { + if (!($media instanceof MediaInterface) || !($media->getSource() instanceof OEmbed)) { return; } diff --git a/core/modules/media/src/Plugin/media/Source/OEmbed.php b/core/modules/media/src/Plugin/media/Source/OEmbed.php index 6cc2c063d3..c75fbd3a66 100644 --- a/core/modules/media/src/Plugin/media/Source/OEmbed.php +++ b/core/modules/media/src/Plugin/media/Source/OEmbed.php @@ -145,10 +145,10 @@ public function getMetadataAttributes() { * {@inheritdoc} */ public function getMetadata(MediaInterface $media, $name) { - $resource_url = $this->getSourceFieldValue($media); + $media_url = $this->getSourceFieldValue($media); try { - $resource_url = $this->resourceFetcher->getResourceUrl($resource_url); + $resource_url = $this->resourceFetcher->getResourceUrl($media_url); $resource = $this->resourceFetcher->fetchResource($resource_url); } catch (ResourceException $e) { @@ -174,12 +174,7 @@ public function getMetadata(MediaInterface $media, $name) { return NULL; case 'thumbnail_local_uri': - $image_url = $this->getMetadata($media, 'thumbnail_url'); - if ($image_url) { - $filename = $this->getMetadata($media, 'provider_name') . '_' . substr(md5($resource_url), 0, 5); - return $this->getLocalImageUri($filename, $image_url); - } - return NULL; + return $this->getLocalImageUri($media, $resource_url); case 'default_name': if ($title = $this->getMetadata($media, 'title')) { @@ -259,15 +254,20 @@ public function defaultConfiguration() { /** * Computes the destination URI for a thumbnail. * - * @param string $filename - * Filename without the extension. - * @param string $remote_url - * The remote URL of the thumbnail. + * @param \Drupal\media\MediaInterface $media + * A media item. + * @param string $resource_url + * The resource URL of oEmbed item. * * @return string * The local URI. */ - protected function getLocalImageUri($filename, $remote_url) { + protected function getLocalImageUri(MediaInterface $media, $resource_url) { + $remote_url = $this->getMetadata($media, 'thumbnail_url'); + if (!$remote_url) { + return parent::getMetadata($media, 'thumbnail_uri'); + } + $directory = $this->configuration['thumbnails_location']; // Ensure that the destination directory is writable. If not, log a warning // and return the default thumbnail. @@ -276,29 +276,16 @@ protected function getLocalImageUri($filename, $remote_url) { $this->logger->warning('Could not prepare thumbnail destination directory @dir for oEmbed media.', [ '@dir' => $directory, ]); - $default_thumbnail_filename = $this->pluginDefinition['default_thumbnail_filename']; - return $this->configFactory->get('media.settings')->get('icon_base_uri') . '/' . $default_thumbnail_filename; + return parent::getMetadata($media, 'thumbnail_uri'); } + $filename = $this->getMetadata($media, 'provider_name') . '_' . substr(md5($resource_url), 0, 5); $local_uri = $this->configuration['thumbnails_location'] . '/' . $filename . '.'; $local_uri .= pathinfo($remote_url, PATHINFO_EXTENSION); return $local_uri; } - /** - * {@inheritdoc} - */ - public function createSourceField(MediaTypeInterface $type) { - return parent::createSourceField($type); - - $settings = $field->getSettings(); - $settings['title'] = DRUPAL_DISABLED; - $settings['link_type'] = LinkItemInterface::LINK_EXTERNAL; - - return $field->set('settings', $settings); - } - /** * {@inheritdoc} */ diff --git a/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php b/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php index ebe6ef0c10..d7a07a9f76 100644 --- a/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php +++ b/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php @@ -21,6 +21,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { 'description' => t('Use remote video URL for reusable media.'), 'supported_providers' => ['YouTube', 'Vimeo'], 'settings' => [], + 'default_thumbnail_filename' => 'video.png', ] + $base_plugin_definition, ]; diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 7330608c96..0fd4b26bdc 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -984,7 +984,7 @@ function system_requirements($phase) { } } // Check to see if dates will be limited to 1901-2038. - if (0) { + if (PHP_INT_SIZE <= 4) { $requirements['limited_date_range'] = [ 'title' => t('Limited date range'), 'value' => t('Your PHP installation has a limited date range.'), diff --git a/core/profiles/standard/config/optional/core.entity_form_display.media.remote_video.default.yml b/core/profiles/standard/config/optional/core.entity_form_display.media.remote_video.default.yml index 6db37117a1..657373cd36 100644 --- a/core/profiles/standard/config/optional/core.entity_form_display.media.remote_video.default.yml +++ b/core/profiles/standard/config/optional/core.entity_form_display.media.remote_video.default.yml @@ -4,7 +4,7 @@ dependencies: config: - field.field.media.remote_video.field_media_oembed_remote_video - media.type.remote_video -id: media.video.default +id: media.remote_video.default targetEntityType: media bundle: remote_video mode: default diff --git a/core/profiles/standard/config/optional/core.entity_view_display.media.remote_video.default.yml b/core/profiles/standard/config/optional/core.entity_view_display.media.remote_video.default.yml index e76dee47f3..8e35beb4d4 100644 --- a/core/profiles/standard/config/optional/core.entity_view_display.media.remote_video.default.yml +++ b/core/profiles/standard/config/optional/core.entity_view_display.media.remote_video.default.yml @@ -9,7 +9,7 @@ dependencies: - image - media - user -id: media.video.default +id: media.remote_video.default targetEntityType: media bundle: remote_video mode: default diff --git a/core/profiles/standard/config/optional/field.field.media.remote_video.field_media_oembed_remote_video.yml b/core/profiles/standard/config/optional/field.field.media.remote_video.field_media_oembed_remote_video.yml index 340399b0fc..2743bd19b2 100644 --- a/core/profiles/standard/config/optional/field.field.media.remote_video.field_media_oembed_remote_video.yml +++ b/core/profiles/standard/config/optional/field.field.media.remote_video.field_media_oembed_remote_video.yml @@ -4,7 +4,7 @@ dependencies: config: - field.storage.media.field_media_oembed_remote_video - media.type.remote_video -id: media.video.field_media_oembed_remote_video +id: media.remote_video.field_media_oembed_remote_video field_name: field_media_oembed_remote_video entity_type: media bundle: remote_video