Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3475695 by joshua1234511, richardgaunt, sime, toby-wild: civictheme_media_get_variables not returning anything for civictheme_remote_video media type #1316

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions web/themes/contrib/civictheme/includes/utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make it more extensible with:

Suggested change
if ($media->bundle() === 'civictheme_remote_video') {
if ($media->getSource() instanceof \Drupal\media\Plugin\media\Source\OEmbed) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated to use $source->getMetadata($media, 'url')
and not specific 'field_c_m_oembed_video' field.

Reference
Screenshot 2024-11-19 at 8 53 46 AM

$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;
Expand All @@ -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;
}

/**
Expand Down
Loading