makes $page optional

This commit is contained in:
buttle 2021-10-13 14:46:49 +02:00
parent f58b75700c
commit d2f9c6ae81
1 changed files with 11 additions and 9 deletions

View File

@ -20,16 +20,18 @@ class HeaderImageViewHelper extends AbstractHelper
* @param SitePageRepresentation
* @return string media url
*/
public function getImage($page)
public function getImage($page = null)
{
foreach ($page->blocks() as $block) {
if ($block->layout() === 'headerImage') {
$attachments = $block->attachments();
#if ($$attachments) {
$media = $attachments[0]->item()->media()[0];
return $media->primaryMedia()->thumbnailUrl('large');
#}
}
if ($page) {
foreach ($page->blocks() as $block) {
if ($block->layout() === 'headerImage') {
$attachments = $block->attachments();
#if ($$attachments) {
$media = $attachments[0]->item()->media()[0];
return $media->primaryMedia()->thumbnailUrl('large');
#}
}
}
}
$site = $this->currentSite();
return $this->getView()->getHelperPluginManager()->get('archiveSiteMeta')->getSiteImage($site);