Replace all magic calls to special tags
This commit is contained in:
parent
42bcd39453
commit
951b227efc
@ -12,10 +12,13 @@ readonly class SnipFilterRequest implements CachableDtoInterface
|
|||||||
public const string SORT_NAME = 'name';
|
public const string SORT_NAME = 'name';
|
||||||
public const string SORT_DATE = 'date';
|
public const string SORT_DATE = 'date';
|
||||||
|
|
||||||
|
public const string TAG_ALL = 'all';
|
||||||
|
public const string TAG_NONE = 'none';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public ?string $visibility = self::VISIBILITY_VISIBLE,
|
public ?string $visibility = self::VISIBILITY_VISIBLE,
|
||||||
public ?string $sort = self::SORT_DATE,
|
public ?string $sort = self::SORT_NAME,
|
||||||
public ?string $tag = 'all',
|
public ?string $tag = self::TAG_ALL,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Dto\SnipFilterRequest;
|
||||||
use App\Repository\TagRepository;
|
use App\Repository\TagRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -18,8 +19,8 @@ class Tag
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Assert\NotEqualTo('all')]
|
#[Assert\NotEqualTo(SnipFilterRequest::TAG_ALL)]
|
||||||
#[Assert\NotEqualTo('none')]
|
#[Assert\NotEqualTo(SnipFilterRequest::TAG_NONE)]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne]
|
#[ORM\ManyToOne]
|
||||||
|
@ -82,7 +82,7 @@ class TagsType extends AbstractType implements DataTransformerInterface
|
|||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => null, // No specific entity class
|
'data_class' => null, // No specific entity class
|
||||||
'label' => 'Tags (comma-separated)',
|
'label' => 'Tags (comma-separated)',
|
||||||
'attr' => ['class' => 'tags-input'], // Optional: Add custom attributes
|
'required' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Twig\Extension;
|
namespace App\Twig\Extension;
|
||||||
|
|
||||||
|
use App\Dto\SnipFilterRequest;
|
||||||
use App\Repository\TagRepository;
|
use App\Repository\TagRepository;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
@ -17,16 +18,24 @@ class SnipFilterExtension extends AbstractExtension
|
|||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('snipSortOptions', fn() => ['name', 'date']),
|
new TwigFunction('snipSortOptions', fn() => [
|
||||||
new TwigFunction('snipFilterOptions', fn() => ['all', 'visible', 'hidden', 'archived']),
|
SnipFilterRequest::SORT_NAME,
|
||||||
|
SnipFilterRequest::SORT_DATE,
|
||||||
|
]),
|
||||||
|
new TwigFunction('snipFilterOptions', fn() => [
|
||||||
|
SnipFilterRequest::VISIBILITY_ALL,
|
||||||
|
SnipFilterRequest::VISIBILITY_VISIBLE,
|
||||||
|
SnipFilterRequest::VISIBILITY_HIDDEN,
|
||||||
|
SnipFilterRequest::VISIBILITY_ARCHIVED,
|
||||||
|
]),
|
||||||
new TwigFunction('snipTagOptions', fn() => $this->getSnipTagOptions()),
|
new TwigFunction('snipTagOptions', fn() => $this->getSnipTagOptions()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSnipTagOptions(): array
|
private function getSnipTagOptions(): array
|
||||||
{
|
{
|
||||||
$tags['all'] = 'All tags';
|
$tags[SnipFilterRequest::TAG_ALL] = 'All tags';
|
||||||
$tags['none'] = 'No tags';
|
$tags[SnipFilterRequest::TAG_NONE] = 'No tags';
|
||||||
foreach ($this->tagRepository->findAllByUser($this->security->getUser()) as $tag) {
|
foreach ($this->tagRepository->findAllByUser($this->security->getUser()) as $tag) {
|
||||||
$tags[(string)$tag] = (string)$tag;
|
$tags[(string)$tag] = (string)$tag;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user