Skip to content

Commit

Permalink
Tolerate missing assets/pages in asset block
Browse files Browse the repository at this point in the history
  • Loading branch information
zerocrates committed Feb 1, 2022
1 parent a7496c9 commit 6007661
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions application/src/Site/BlockLayout/Asset.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Omeka\Site\BlockLayout;

use Omeka\Api\Exception as ApiException;
use Omeka\Api\Representation\SiteRepresentation;
use Omeka\Api\Representation\SitePageRepresentation;
use Omeka\Api\Representation\SitePageBlockRepresentation;
Expand Down Expand Up @@ -61,13 +62,21 @@ public function prepareAssetAttachments(PhpRenderer $view, $blockData = null)
if (isset($value['id'])) {
if ($value['id'] !== '') {
$assetId = $value['id'];
$asset = $view->api()->read('assets', $assetId)->getContent();
$attachments[$key]['asset'] = $asset;
try {
$asset = $view->api()->read('assets', $assetId)->getContent();
$attachments[$key]['asset'] = $asset;
} catch (ApiException\NotFoundException $e) {
$attachments[$key]['asset'] = null;
}
} else {
$attachments[$key]['asset'] = null;
}
if ($value['page'] !== '') {
$attachments[$key]['page'] = $view->api()->read('site_pages', $value['page'])->getContent();
try {
$attachments[$key]['page'] = $view->api()->read('site_pages', $value['page'])->getContent();
} catch (ApiException\NotFoundException $e) {
// do nothing
}
}
$attachments[$key]['alt_link_title'] = $value['alt_link_title'];
$attachments[$key]['caption'] = $value['caption'];
Expand Down

0 comments on commit 6007661

Please sign in to comment.