Skip to content

Commit

Permalink
Fix album name validation and photo upload exception
Browse files Browse the repository at this point in the history
Also fixes that error messages for the `Regex` validators are
actually shown.
  • Loading branch information
tomudding committed Feb 8, 2024
1 parent 637a3da commit 7bf1f58
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion module/Company/src/Form/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-\.]+$/',
'messages' => [
Regex::ERROROUS => $this->getTranslator()->translate(
Regex::NOT_MATCH => $this->getTranslator()->translate(
'This slug contains invalid characters',
),
],
Expand Down
2 changes: 1 addition & 1 deletion module/Company/src/Form/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-\.]+$/',
'messages' => [
Regex::ERROROUS => $this->getTranslator()->translate(
Regex::NOT_MATCH => $this->getTranslator()->translate(
'This slug contains invalid characters',
),
],
Expand Down
2 changes: 1 addition & 1 deletion module/Company/src/Form/JobCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-\.]*$/',
'messages' => [
Regex::ERROROUS => $this->translator->translate(
Regex::NOT_MATCH => $this->translator->translate(
'This slug contains invalid characters',
),
],
Expand Down
2 changes: 1 addition & 1 deletion module/Company/src/Form/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-\.\s]+$/',
'messages' => [
Regex::ERROROUS => $this->getTranslator()->translate(
Regex::NOT_MATCH => $this->getTranslator()->translate(
'Contract numbers can only contain letters, numbers, _, -, ., and spaces',
),
],
Expand Down
6 changes: 3 additions & 3 deletions module/Frontpage/src/Form/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-]+$/',
'messages' => [
Regex::ERROROUS => $this->translator->translate(
Regex::NOT_MATCH => $this->translator->translate(
'This route part contains invalid characters.',
),
],
Expand Down Expand Up @@ -312,7 +312,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-]+$/',
'messages' => [
Regex::ERROROUS => $this->translator->translate(
Regex::NOT_MATCH => $this->translator->translate(
'This route part contains invalid characters.',
),
],
Expand Down Expand Up @@ -343,7 +343,7 @@ public function getInputFilterSpecification(): array
'options' => [
'pattern' => '/^[0-9a-zA-Z_\-]+$/',
'messages' => [
Regex::ERROROUS => $this->translator->translate(
Regex::NOT_MATCH => $this->translator->translate(
'This route part contains invalid characters.',
),
],
Expand Down
5 changes: 4 additions & 1 deletion module/Photo/src/Controller/AlbumAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@ public function addAction(): ViewModel
$albumId = (int) $this->params()->fromRoute('album_id');
$album = $this->albumService->getAlbum($albumId);

$start = $album->getStartDateTime();
$year = (null === $start) ? null : AssociationYear::fromDate($start)->getYear();

Check failure on line 202 in module/Photo/src/Controller/AlbumAdminController.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Useless parentheses.

return new ViewModel(
[
'album' => $album,
'year' => AssociationYear::fromDate($album->getStartDateTime())->getYear(),
'year' => $year,
],
);
}
Expand Down
23 changes: 14 additions & 9 deletions module/Photo/src/Form/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
use Laminas\Form\Element\Submit;
use Laminas\Form\Element\Text;
use Laminas\Form\Form;
use Laminas\I18n\Validator\Alnum;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Mvc\I18n\Translator;
use Laminas\Validator\NotEmpty;
use Laminas\Validator\Regex;
use Laminas\Validator\StringLength;

class Album extends Form implements InputFilterProviderInterface
{
public function __construct(Translator $translate)
public function __construct(private Translator $translator)
{
parent::__construct();

Expand All @@ -26,7 +26,7 @@ public function __construct(Translator $translate)
'name' => 'name',
'type' => Text::class,
'options' => [
'label' => $translate->translate('Album title'),
'label' => $this->translator->translate('Album title'),
],
],
);
Expand All @@ -36,7 +36,7 @@ public function __construct(Translator $translate)
'name' => 'startDateTime',
'type' => DateTimeLocal::class,
'options' => [
'label' => $translate->translate('Start date'),
'label' => $this->translator->translate('Start date'),
'format' => 'Y-m-d\TH:i',
],
],
Expand All @@ -47,7 +47,7 @@ public function __construct(Translator $translate)
'name' => 'endDateTime',
'type' => DateTimeLocal::class,
'options' => [
'label' => $translate->translate('End date'),
'label' => $this->translator->translate('End date'),
'format' => 'Y-m-d\TH:i',
],
],
Expand All @@ -58,7 +58,7 @@ public function __construct(Translator $translate)
'name' => 'published',
'type' => Checkbox::class,
'options' => [
'label' => $translate->translate('Published'),
'label' => $this->translator->translate('Published'),
'checked_value' => '1',
'unchecked_value' => '0',
],
Expand All @@ -73,7 +73,7 @@ public function __construct(Translator $translate)
'name' => 'submit',
'type' => Submit::class,
'options' => [
'label' => $translate->translate('Save'),
'label' => $this->translator->translate('Save'),
],
],
);
Expand All @@ -92,9 +92,14 @@ public function getInputFilterSpecification(): array
'name' => NotEmpty::class,
],
[
'name' => Alnum::class,
'name' => Regex::class,
'options' => [
'allowWhiteSpace' => true,
'pattern' => '/^[0-9a-zA-Z\-\.\:\'\"\s]+$/',
'messages' => [
Regex::NOT_MATCH => $this->translator->translate(
'Album name can only contain letters, numbers, -, ., :, \', ", and spaces',
),
],
],
],
[
Expand Down
25 changes: 23 additions & 2 deletions module/Photo/view/photo/album-admin/add.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Photo\Model\Album as AlbumModel;
/**
* @var PhpRenderer|HelperTrait $this
* @var AlbumModel $album
* @var int|null $year
*/

$this->inlineScript()
Expand All @@ -30,8 +31,28 @@ $this->inlineScript()
$this->headLink()->appendStylesheet($this->basepath('css/dropzone.css'));

$this->breadcrumbs()
->addBreadcrumb($this->translate('Photos'), true, $this->url('admin_photo'))
->addBreadcrumb(sprintf('%d/%d', $year, $year + 1), true, $this->url('admin_photo/album_year', ['year' => $year]));
->addBreadcrumb($this->translate('Photos'), true, $this->url('admin_photo'));

if (null === $year) {
$this->breadcrumbs()
->addBreadcrumb(
$this->translate('Undated'),
true,
$this->url('admin_photo/album_undated'),
);
} else {
$this->breadcrumbs()
->addBreadcrumb(
sprintf(
'%d/%d',
$year,
$year + 1,
),
true,
$this->url('admin_photo/album_year', ['year' => $year]),
);
}


if (null !== $album->getParent()) {
$parents = [];
Expand Down

0 comments on commit 7bf1f58

Please sign in to comment.