Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Check if paragraph field exists
Browse files Browse the repository at this point in the history
  • Loading branch information
feroivanko committed Nov 16, 2018
1 parent 2b08948 commit 61914b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions paragraphs_types.module
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ function paragraphs_types_preprocess_paragraph__video(&$variables) {
function paragraphs_types_preprocess_paragraph__gallery(&$variables) {
/** @var Paragraph $paragraph */
$paragraph = $variables['paragraph'];

if (!$paragraph->hasField('field_images')) {
return;
}

$images = $paragraph->get('field_images');

$variables['images'] = [];
Expand Down Expand Up @@ -174,6 +179,12 @@ function paragraphs_types_preprocess_paragraph__gallery(&$variables) {
function paragraphs_types_preprocess_paragraph__image(&$variables) {
/** @var Paragraph $paragraph */
$paragraph = $variables['paragraph'];

if (!$paragraph->hasField('field_image')) {
return;
}


$imageField = $paragraph->get('field_image')->first();

if(!$imageField instanceof ImageItem || (int) $imageField->target_id <= 0 ) {
Expand Down

0 comments on commit 61914b5

Please sign in to comment.