forked from Public/pics
EditAlbum: fix error handling
This commit is contained in:
parent
2bfbe67d91
commit
45b59636f6
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
class EditAlbum extends HTMLController
|
class EditAlbum extends HTMLController
|
||||||
{
|
{
|
||||||
|
private $form;
|
||||||
|
private $formview;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// Ensure it's just admins at this point.
|
// Ensure it's just admins at this point.
|
||||||
@ -117,7 +120,7 @@ class EditAlbum extends HTMLController
|
|||||||
unset($fields['id_asset_thumb']);
|
unset($fields['id_asset_thumb']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new Form([
|
$this->form = new Form([
|
||||||
'request_url' => BASEURL . '/editalbum/?' . ($id_tag ? 'id=' . $id_tag : 'add'),
|
'request_url' => BASEURL . '/editalbum/?' . ($id_tag ? 'id=' . $id_tag : 'add'),
|
||||||
'content_below' => $after_form,
|
'content_below' => $after_form,
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
@ -141,9 +144,9 @@ class EditAlbum extends HTMLController
|
|||||||
$formDefaults = isset($album) ? get_object_vars($album) : $_POST;
|
$formDefaults = isset($album) ? get_object_vars($album) : $_POST;
|
||||||
|
|
||||||
// Create the form, add in default values.
|
// Create the form, add in default values.
|
||||||
$form->setData($formDefaults);
|
$this->form->setData($formDefaults);
|
||||||
$formview = new FormView($form, $form_title ?? '');
|
$this->formview = new FormView($this->form, $form_title ?? '');
|
||||||
$this->page->adopt($formview);
|
$this->page->adopt($this->formview);
|
||||||
|
|
||||||
// If we have asset images, show the thumbnail manager
|
// If we have asset images, show the thumbnail manager
|
||||||
if (!empty($id_tag) && $num_assets > 0)
|
if (!empty($id_tag) && $num_assets > 0)
|
||||||
@ -152,7 +155,7 @@ class EditAlbum extends HTMLController
|
|||||||
if (isset($_POST['changeThumbnail']))
|
if (isset($_POST['changeThumbnail']))
|
||||||
$this->processThumbnail($album);
|
$this->processThumbnail($album);
|
||||||
elseif (!empty($_POST))
|
elseif (!empty($_POST))
|
||||||
$this->processTagDetails($form, $id_tag, $album ?? null);
|
$this->processTagDetails($id_tag, $album ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processThumbnail($tag)
|
private function processThumbnail($tag)
|
||||||
@ -167,22 +170,22 @@ class EditAlbum extends HTMLController
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processTagDetails($form, $id_tag, $album)
|
private function processTagDetails($id_tag, $album)
|
||||||
{
|
{
|
||||||
if (!empty($_POST))
|
if (!empty($_POST))
|
||||||
{
|
{
|
||||||
$form->verify($_POST);
|
$this->form->verify($_POST);
|
||||||
|
|
||||||
// Anything missing?
|
// Anything missing?
|
||||||
if (!empty($form->getMissing()))
|
if (!empty($this->form->getMissing()))
|
||||||
return $formview->adopt(new Alert('Some data missing', 'Please fill out the following fields: ' . implode(', ', $form->getMissing()), 'danger'));
|
return $this->formview->adopt(new Alert('Some data missing', 'Please fill out the following fields: ' . implode(', ', $this->form->getMissing()), 'danger'));
|
||||||
|
|
||||||
$data = $form->getData();
|
$data = $this->form->getData();
|
||||||
|
|
||||||
// Sanity check: don't let an album be its own parent
|
// Sanity check: don't let an album be its own parent
|
||||||
if ($data['id_parent'] == $id_tag)
|
if ($data['id_parent'] == $id_tag)
|
||||||
{
|
{
|
||||||
return $formview->adopt(new Alert('Invalid parent', 'An album cannot be its own parent.', 'danger'));
|
return $this->formview->adopt(new Alert('Invalid parent', 'An album cannot be its own parent.', 'danger'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quick stripping.
|
// Quick stripping.
|
||||||
@ -198,7 +201,7 @@ class EditAlbum extends HTMLController
|
|||||||
$data['kind'] = 'Album';
|
$data['kind'] = 'Album';
|
||||||
$newTag = Tag::createNew($data);
|
$newTag = Tag::createNew($data);
|
||||||
if ($newTag === false)
|
if ($newTag === false)
|
||||||
return $formview->adopt(new Alert('Cannot create this album', 'Something went wrong while creating the album...', 'danger'));
|
return $this->formview->adopt(new Alert('Cannot create this album', 'Something went wrong while creating the album...', 'danger'));
|
||||||
|
|
||||||
if (isset($_POST['submit_and_new']))
|
if (isset($_POST['submit_and_new']))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user