*/ #[ORM\OneToMany(mappedBy: 'customFieldGroup', targetEntity: CustomField::class)] #[ORM\OrderBy(['ordering' => \Doctrine\Common\Collections\Criteria::ASC])] private Collection $customFields; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] private ?string $entity = null; #[ORM\Id] #[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)] #[ORM\GeneratedValue(strategy: 'AUTO')] private ?int $id = null; /** * @var array */ #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)] private $name; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)] private array $options = []; /** * CustomFieldsGroup constructor. */ public function __construct() { $this->customFields = new ArrayCollection(); } /** * Add customField. * * @return CustomFieldsGroup */ public function addCustomField(CustomField $customField) { $this->customFields[] = $customField; return $this; } /** * Get all the custom. */ public function getActiveCustomFields(): array { if (null === $this->activeCustomFields) { $this->activeCustomFields = []; foreach ($this->customFields as $cf) { if ($cf->isActive()) { $this->activeCustomFields[] = $cf; } } } return $this->activeCustomFields; } /** * @return Collection */ public function getCustomFields() { return $this->customFields; } /** * Get entity. * * @return string */ public function getEntity() { return $this->entity; } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Get name. */ public function getName(?string $language = null): array|string { // TODO set this in a service, PLUS twig function if (null !== $language) { if (isset($this->name[$language])) { return $this->name[$language]; } foreach ($this->name as $name) { if (!empty($name)) { return $name; } } return ''; } return $this->name; } /** * get options array. * * @return array */ public function getOptions() { return $this->options; } /** * Remove customField. */ public function removeCustomField(CustomField $customField) { $this->customFields->removeElement($customField); } /** * Set entity. * * @return CustomFieldsGroup */ public function setEntity(?string $entity) { $this->entity = $entity; return $this; } /** * Set name. * * @param array $name * * @return CustomFieldsGroup */ public function setName($name) { $this->name = $name; return $this; } /** * set options array. * * @return CustomFieldsGroup */ public function setOptions(array $options) { $this->options = $options; return $this; } }