Use enums for LabelOptions

This commit is contained in:
Jan Böhmer 2023-06-12 23:39:30 +02:00
parent 485b35fbd4
commit 71cd4057a7
23 changed files with 329 additions and 157 deletions

View file

@ -42,6 +42,7 @@ declare(strict_types=1);
namespace App\Services\LabelSystem;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\LabelSystem\LabelSupportedElement;
use App\Repository\LabelProfileRepository;
use App\Services\UserSystem\UserCacheKeyGenerator;
use Doctrine\ORM\EntityManagerInterface;
@ -54,10 +55,20 @@ final class LabelProfileDropdownHelper
{
}
public function getDropdownProfiles(string $type): array
/**
* Return all label profiles for the given supported element type
* @param LabelSupportedElement|string $type
* @return array
*/
public function getDropdownProfiles(LabelSupportedElement|string $type): array
{
//Useful for the twig templates, where we use the string representation of the enum
if (is_string($type)) {
$type = LabelSupportedElement::from($type);
}
$secure_class_name = str_replace('\\', '_', LabelProfile::class);
$key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name.'_'.$type;
$key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name.'_'.$type->value;
/** @var LabelProfileRepository $repo */
$repo = $this->entityManager->getRepository(LabelProfile::class);