Skip to content

Commit

Permalink
OEL-2258: Featured-media processing text and link without media images.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiberiu Dumitru committed Apr 25, 2023
1 parent 695f830 commit d7bc714
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions modules/oe_whitelabel_paragraphs/oe_whitelabel_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ function oe_whitelabel_preprocess_paragraph__oe_text_feature_media(array &$varia
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];

$variant = $paragraph->get('oe_paragraphs_variant')->value ?? 'default';
$variables['text_position'] = str_replace([
'_featured',
'_simple',
], '', $variant);

if (empty($paragraph->get('field_oe_link')->first())) {
return;
}

/** @var \Drupal\link\Plugin\Field\FieldType\LinkItem $link_item */
$link_item = $paragraph->get('field_oe_link')->first();
$variables['link'] = [
'path' => $link_item->getUrl(),
'label' => $link_item->get('title')->getValue(),
];

$cacheability->applyTo($variables);

// Bail out if there is no media present.
if ($paragraph->get('field_oe_media')->isEmpty()) {
return;
Expand Down Expand Up @@ -181,12 +200,6 @@ function oe_whitelabel_preprocess_paragraph__oe_text_feature_media(array &$varia
return;
}

$variant = $paragraph->get('oe_paragraphs_variant')->value ?? 'default';
$variables['text_position'] = str_replace([
'_featured',
'_simple',
], '', $variant);

if ($is_image) {
$thumbnail = $media->get('thumbnail')->first();
$variables['image'] = ImageValueObject::fromStyledImageItem($thumbnail, 'oe_bootstrap_theme_medium_no_crop');
Expand All @@ -197,16 +210,6 @@ function oe_whitelabel_preprocess_paragraph__oe_text_feature_media(array &$varia

$cacheability->applyTo($variables);

if (empty($paragraph->get('field_oe_link')->first())) {
return;
}

/** @var \Drupal\link\Plugin\Field\FieldType\LinkItem $link_item */
$link_item = $paragraph->get('field_oe_link')->first();
$variables['link'] = [
'path' => $link_item->getUrl(),
'label' => $link_item->get('title')->getValue(),
];
}

/**
Expand Down

0 comments on commit d7bc714

Please sign in to comment.