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