Release 2.45 (#5721)
Co-authored-by: Henning Klein <info@henningklein.de>
This commit is contained in:
@@ -11,6 +11,7 @@ namespace App\Entity;
|
||||
|
||||
use App\Constants;
|
||||
use App\Export\Annotation as Exporter;
|
||||
use App\Utils\Color;
|
||||
use App\Validator\Constraints as Constraints;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -22,8 +23,7 @@ trait ColorTrait
|
||||
* The assigned color in HTML hex format, e.g. #dd1d00
|
||||
*/
|
||||
#[ORM\Column(name: 'color', type: Types::STRING, length: 7, nullable: true)]
|
||||
#[Serializer\Expose]
|
||||
#[Serializer\Groups(['Default'])]
|
||||
#[Serializer\Exclude]
|
||||
#[Exporter\Expose(label: 'color')]
|
||||
#[Constraints\HexColor]
|
||||
private ?string $color = null;
|
||||
@@ -46,4 +46,17 @@ trait ColorTrait
|
||||
{
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
abstract public function getName(): ?string;
|
||||
|
||||
/**
|
||||
* Internal value: this color will never be empty and is generated by the tag name if not set explicit.
|
||||
*/
|
||||
#[Serializer\VirtualProperty]
|
||||
#[Serializer\SerializedName('color')]
|
||||
#[Serializer\Groups(['Default'])]
|
||||
public function getColorSafe(): string
|
||||
{
|
||||
return $this->getColor() ?? (new Color())->getRandom($this->getName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user