From f26fc0de50bbc2b5ad0d5b58d2033a0c297c7026 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Wed, 13 Nov 2024 22:43:59 +0530 Subject: [PATCH 1/2] [3475695] Updated civictheme_media_get_variables to handle the OEmbed (remote video). --- .../contrib/civictheme/includes/utilities.inc | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/web/themes/contrib/civictheme/includes/utilities.inc b/web/themes/contrib/civictheme/includes/utilities.inc index 5e527f70e..3c87d9fe1 100644 --- a/web/themes/contrib/civictheme/includes/utilities.inc +++ b/web/themes/contrib/civictheme/includes/utilities.inc @@ -120,6 +120,19 @@ function civictheme_get_layout_builder_settings_per_view_mode(string $entity_typ * @SuppressWarnings(PHPMD.StaticAccess) */ function civictheme_media_get_variables(MediaInterface $media): ?array { + $variables = [ + 'media_name' => t('@name', ['@name' => $media->label()]), + 'created' => civictheme_format_datetime((int) $media->getCreatedTime(), 'civictheme_short_date'), + 'changed' => civictheme_format_datetime($media->getChangedTime(), 'civictheme_short_date'), + ]; + + if ($media->bundle() === 'civictheme_remote_video') { + $variables['name'] = t('@name', ['@name' => $media->label()]); + $variables['url'] = \Drupal::service('media.oembed.url_resolver') + ->getResourceUrl($media->get('field_c_m_oembed_video')->first()->getValue()['value']); + return $variables; + } + $fid = $media->getSource()->getSourceFieldValue($media); /** @var \Drupal\file\FileInterface|null $file */ $file = $fid ? File::load($fid) : NULL; @@ -128,16 +141,15 @@ function civictheme_media_get_variables(MediaInterface $media): ?array { return NULL; } - return [ + $variables += [ 'name' => t('@name', ['@name' => $file->label()]), - 'media_name' => t('@name', ['@name' => $media->label()]), 'ext' => pathinfo((string) $file->getFileUri(), PATHINFO_EXTENSION) ?: '', 'url' => civictheme_media_get_url($media), 'size' => ByteSizeMarkup::create($file->getSize()), - 'created' => civictheme_format_datetime((int) $media->getCreatedTime(), 'civictheme_short_date'), - 'changed' => civictheme_format_datetime($media->getChangedTime(), 'civictheme_short_date'), 'icon' => civictheme_get_icon_from_file($file), ]; + + return $variables; } /** From 75dfce5364e7fbe75c5a085a7052ced5c7498445 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Tue, 19 Nov 2024 08:52:47 +0530 Subject: [PATCH 2/2] [3475695] Updated civictheme_media_get_variables to handle the OEmbed (remote video) in Generic. --- web/themes/contrib/civictheme/includes/utilities.inc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/themes/contrib/civictheme/includes/utilities.inc b/web/themes/contrib/civictheme/includes/utilities.inc index 3c87d9fe1..cc336d0fa 100644 --- a/web/themes/contrib/civictheme/includes/utilities.inc +++ b/web/themes/contrib/civictheme/includes/utilities.inc @@ -24,6 +24,7 @@ use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\image\Entity\ImageStyle; use Drupal\media\MediaInterface; +use Drupal\media\Plugin\media\Source\OEmbedInterface; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; use Drupal\paragraphs\Entity\Paragraph; @@ -125,11 +126,13 @@ function civictheme_media_get_variables(MediaInterface $media): ?array { 'created' => civictheme_format_datetime((int) $media->getCreatedTime(), 'civictheme_short_date'), 'changed' => civictheme_format_datetime($media->getChangedTime(), 'civictheme_short_date'), ]; - - if ($media->bundle() === 'civictheme_remote_video') { + $source = $media->getSource(); + if ($source instanceof OEmbedInterface) { $variables['name'] = t('@name', ['@name' => $media->label()]); - $variables['url'] = \Drupal::service('media.oembed.url_resolver') - ->getResourceUrl($media->get('field_c_m_oembed_video')->first()->getValue()['value']); + $url = $source->getMetadata($media, 'url'); + if (!empty($url)) { + $variables['url'] = $url; + } return $variables; }