EditAlbum: allow specifying a thumbnail ID manually if none are present

This commit is contained in:
Aaron van Geffen 2023-03-11 20:46:31 +01:00
parent 5cff62836e
commit 5b8551a726

View File

@ -72,15 +72,17 @@ class EditAlbum extends HTMLController
$parentChoices[$parent['id_tag']] = $parent['tag']; $parentChoices[$parent['id_tag']] = $parent['tag'];
} }
$form = new Form([ $fields = [
'request_url' => BASEURL . '/editalbum/?' . ($id_tag ? 'id=' . $id_tag : 'add'),
'content_below' => $after_form,
'fields' => [
'id_parent' => [ 'id_parent' => [
'type' => 'select', 'type' => 'select',
'label' => 'Parent album', 'label' => 'Parent album',
'options' => $parentChoices, 'options' => $parentChoices,
], ],
'id_asset_thumb' => [
'type' => 'numeric',
'label' => 'Thumbnail asset ID',
'is_optional' => true,
],
'tag' => [ 'tag' => [
'type' => 'text', 'type' => 'text',
'label' => 'Album title', 'label' => 'Album title',
@ -100,9 +102,28 @@ class EditAlbum extends HTMLController
'maxlength' => 255, 'maxlength' => 255,
'is_optional' => true, 'is_optional' => true,
], ],
], ];
// Fetch image assets for this album
if (!empty($id_tag))
{
list($assets, $num_assets) = AssetIterator::getByOptions([
'direction' => 'desc',
'limit' => 500,
'id_tag' => $id_tag,
], true);
if ($num_assets > 0)
unset($fields['id_asset_thumb']);
}
$form = new Form([
'request_url' => BASEURL . '/editalbum/?' . ($id_tag ? 'id=' . $id_tag : 'add'),
'content_below' => $after_form,
'fields' => $fields,
]); ]);
// Add defaults for album if none present
if (empty($_POST) && isset($_GET['tag'])) if (empty($_POST) && isset($_GET['tag']))
{ {
$parentTag = Tag::fromId($_GET['tag']); $parentTag = Tag::fromId($_GET['tag']);
@ -124,17 +145,9 @@ class EditAlbum extends HTMLController
$formview = new FormView($form, $form_title ?? ''); $formview = new FormView($form, $form_title ?? '');
$this->page->adopt($formview); $this->page->adopt($formview);
if (!empty($id_tag)) // If we have asset images, show the thumbnail manager
{ if (!empty($id_tag) && $num_assets > 0)
list($assets, $num_assets) = AssetIterator::getByOptions([
'direction' => 'desc',
'limit' => 500,
'id_tag' => $id_tag,
], true);
if ($num_assets > 0)
$this->page->adopt(new FeaturedThumbnailManager($assets, $id_tag ? $album->id_asset_thumb : 0)); $this->page->adopt(new FeaturedThumbnailManager($assets, $id_tag ? $album->id_asset_thumb : 0));
}
if (isset($_POST['changeThumbnail'])) if (isset($_POST['changeThumbnail']))
$this->processThumbnail($album); $this->processThumbnail($album);