Skip to content

Commit

Permalink
Merge pull request #831 from SLAC/SLAC22-686-override-caption-2
Browse files Browse the repository at this point in the history
[SLAC22-686] Allow users to toggle boolean when overriding caption on lightbox video
  • Loading branch information
briantschu committed Apr 19, 2023
2 parents 8381bcd + a8ff587 commit 6aa075a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.paragraph.video_lightbox.field_body
- field.field.paragraph.video_lightbox.field_boolean
- field.field.paragraph.video_lightbox.field_video
- paragraphs.paragraphs_type.video_lightbox
module:
Expand All @@ -18,7 +19,7 @@ mode: default
content:
field_body:
type: text_textarea
weight: 1
weight: 2
region: content
settings:
rows: 2
Expand All @@ -27,6 +28,13 @@ content:
allowed_formats:
hide_help: '1'
hide_guidelines: '1'
field_boolean:
type: boolean_checkbox
weight: 1
region: content
settings:
display_label: true
third_party_settings: { }
field_video:
type: media_library_widget
weight: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.paragraph.video_lightbox.field_body
- field.field.paragraph.video_lightbox.field_boolean
- field.field.paragraph.video_lightbox.field_video
- paragraphs.paragraphs_type.video_lightbox
id: paragraph.video_lightbox.default
Expand All @@ -22,4 +23,5 @@ content:
region: content
hidden:
field_body: true
field_boolean: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ id: paragraph.video_lightbox.field_body
field_name: field_body
entity_type: paragraph
bundle: video_lightbox
label: 'Override Caption'
label: 'Override Caption Text'
description: 'If populated, this caption will be displayed below the lightbox instead of the video''s caption from the media library.'
required: false
translatable: true
Expand Down
4 changes: 2 additions & 2 deletions web/themes/gesso/includes/media.inc
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function gesso_preprocess_media(array &$variables) {
$variables['lightbox_id'] = $lightbox_id;
if (isset($variables['content']['field_thumbnail'][0])) {
$variables['content']['field_thumbnail'][0]['#media']->lightbox_id = $lightbox_id;
$variables['content']['field_thumbnail'][0]['#media']->video_caption[] = $video_media->paragraph_override_caption ? $video_media->paragraph_override_caption->view() : $video_media->field_caption->view();
$variables['content']['field_thumbnail'][0]['#media']->video_caption[] = $video_media->paragraph_override_caption ?: $video_media->field_caption->view();
$variables['content']['field_thumbnail'][0]['#media']->video_caption[] = $video_media->field_credit->view();
} elseif (isset($variables['content']['thumbnail'][0])) {
$variables['content']['thumbnail'][0]['#lightbox_id'] = $lightbox_id;
$variables['content']['thumbnail'][0]['#video_caption'][] = $video_media->paragraph_override_caption ? $video_media->paragraph_override_caption->view() : $video_media->field_caption->view();
$variables['content']['thumbnail'][0]['#video_caption'][] = $video_media->paragraph_override_caption ?: $video_media->field_caption->view();
$variables['content']['thumbnail'][0]['#video_caption'][] = $video_media->field_credit->view();
}
// Set the URL to the detail page only if the editor hasn't hidden
Expand Down
12 changes: 7 additions & 5 deletions web/themes/gesso/includes/paragraph.inc
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,17 @@ function gesso_preprocess_paragraph__overlap_image(array &$vars) {
* Implements hook_preprocess_paragraph__HOOK().
*/
function gesso_preprocess_paragraph__video_lightbox(array &$vars) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = !empty($vars['paragraph']) ? $vars['paragraph'] : NULL;
if (isset($vars['paragraph'])) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = $vars['paragraph'];

if ($paragraph) {
// Add the override caption to the media entity, if it exists.
if ($vars['content']['field_video'][0]['#media']) {
if (isset($vars['content']['field_video'][0]['#media'])) {
/** @var \Drupal\Media\entity\Media $media */
$media = $vars['content']['field_video'][0]['#media'];
$media->paragraph_override_caption = !empty($paragraph->field_body[0]) ? $paragraph->field_body : NULL;
if ($paragraph->field_boolean->value) {
$media->paragraph_override_caption = $paragraph->field_body->view() ?? NULL;
}
$media->addCacheableDependency($paragraph);
$media->addCacheContexts(['url']);
}
Expand Down

0 comments on commit 6aa075a

Please sign in to comment.