From 5b8551a72676a08f1bdb698134600d6c0d65f786 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 11 Mar 2023 20:46:31 +0100 Subject: [PATCH] EditAlbum: allow specifying a thumbnail ID manually if none are present --- controllers/EditAlbum.php | 87 ++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/controllers/EditAlbum.php b/controllers/EditAlbum.php index c24787d..6d73428 100644 --- a/controllers/EditAlbum.php +++ b/controllers/EditAlbum.php @@ -72,37 +72,58 @@ class EditAlbum extends HTMLController $parentChoices[$parent['id_tag']] = $parent['tag']; } + $fields = [ + 'id_parent' => [ + 'type' => 'select', + 'label' => 'Parent album', + 'options' => $parentChoices, + ], + 'id_asset_thumb' => [ + 'type' => 'numeric', + 'label' => 'Thumbnail asset ID', + 'is_optional' => true, + ], + 'tag' => [ + 'type' => 'text', + 'label' => 'Album title', + 'size' => 50, + 'maxlength' => 255, + ], + 'slug' => [ + 'type' => 'text', + 'label' => 'URL slug', + 'size' => 50, + 'maxlength' => 255, + ], + 'description' => [ + 'type' => 'textbox', + 'label' => 'Description', + 'size' => 50, + 'maxlength' => 255, + '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' => [ - 'id_parent' => [ - 'type' => 'select', - 'label' => 'Parent album', - 'options' => $parentChoices, - ], - 'tag' => [ - 'type' => 'text', - 'label' => 'Album title', - 'size' => 50, - 'maxlength' => 255, - ], - 'slug' => [ - 'type' => 'text', - 'label' => 'URL slug', - 'size' => 50, - 'maxlength' => 255, - ], - 'description' => [ - 'type' => 'textbox', - 'label' => 'Description', - 'size' => 50, - 'maxlength' => 255, - 'is_optional' => true, - ], - ], + 'fields' => $fields, ]); + // Add defaults for album if none present if (empty($_POST) && isset($_GET['tag'])) { $parentTag = Tag::fromId($_GET['tag']); @@ -124,17 +145,9 @@ class EditAlbum extends HTMLController $formview = new FormView($form, $form_title ?? ''); $this->page->adopt($formview); - if (!empty($id_tag)) - { - 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)); - } + // If we have asset images, show the thumbnail manager + if (!empty($id_tag) && $num_assets > 0) + $this->page->adopt(new FeaturedThumbnailManager($assets, $id_tag ? $album->id_asset_thumb : 0)); if (isset($_POST['changeThumbnail'])) $this->processThumbnail($album);