Skip to content

Commit

Permalink
fix: resolve issue with card component not detecting hasImage correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Oct 14, 2024
1 parent f56d738 commit 6a300c5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions source/php/Component/Card/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,27 @@ public function init()
$this->data['classList'][] = $this->getBaseClass() . '--ratio-' . str_replace(":", "-", $ratio);
}

//Determine if the card has an image
$this->data['imageExists'] = true;
if(is_a($image, 'ComponentLibrary\Integrations\Image\Image')) {
if(empty($image->getUrl())) {
$this->data['imageExists'] = false;
}
} elseif(is_array($image)) {
if ($image && !isset($image['src']) || (isset($image['src']) && empty($image['src']))) {
$this->data['imageExists'] = false;
}
}
$this->data['imageExists'] = $this->hasImage($image);

$this->data['contentHtmlElement'] = $this->getContentHTMLElement($content);
}

/**
* Check if the image is set
*
* @param mixed $image
*
* @return bool
*/
private function hasImage($image) {
if (is_a($image, 'ComponentLibrary\Integrations\Image\Image')) {
return !empty($image->getUrl());
}
if (is_array($image)) {
return !empty($image['src']);
}
return !empty($image);
}

/**
* Get the type of content wrapper that should be used
Expand Down

0 comments on commit 6a300c5

Please sign in to comment.