vendor/sulu/form-bundle/Entity/FormField.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\FormBundle\Entity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. /**
  14. * Form field entity.
  15. */
  16. class FormField
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $key;
  22. /**
  23. * @var string
  24. */
  25. private $type;
  26. /**
  27. * @var string
  28. */
  29. private $width = 'full';
  30. /**
  31. * @var bool
  32. */
  33. private $required = false;
  34. /**
  35. * @var null|int
  36. */
  37. private $id;
  38. /**
  39. * @var int
  40. */
  41. private $order;
  42. /**
  43. * @var string
  44. */
  45. private $defaultLocale;
  46. /**
  47. * @var Collection<int, FormFieldTranslation>
  48. */
  49. private $translations;
  50. /**
  51. * @var Form
  52. */
  53. private $form;
  54. /**
  55. * Constructor.
  56. */
  57. public function __construct()
  58. {
  59. $this->translations = new ArrayCollection();
  60. }
  61. public function getDefaultLocale(): string
  62. {
  63. return $this->defaultLocale;
  64. }
  65. public function setDefaultLocale(string $defaultLocale): self
  66. {
  67. $this->defaultLocale = $defaultLocale;
  68. return $this;
  69. }
  70. public function getOrder(): int
  71. {
  72. return $this->order;
  73. }
  74. public function setOrder(int $order): self
  75. {
  76. $this->order = $order;
  77. return $this;
  78. }
  79. public function setKey(string $key): self
  80. {
  81. $this->key = $key;
  82. return $this;
  83. }
  84. public function getKey(): string
  85. {
  86. return $this->key;
  87. }
  88. public function setType(string $type): self
  89. {
  90. $this->type = $type;
  91. return $this;
  92. }
  93. public function getType(): string
  94. {
  95. return $this->type;
  96. }
  97. public function setWidth(string $width): self
  98. {
  99. $this->width = $width;
  100. return $this;
  101. }
  102. public function getWidth(): string
  103. {
  104. return $this->width;
  105. }
  106. public function setRequired(bool $required): self
  107. {
  108. $this->required = $required;
  109. return $this;
  110. }
  111. public function getRequired(): bool
  112. {
  113. return $this->required;
  114. }
  115. public function getId(): ?int
  116. {
  117. return $this->id;
  118. }
  119. /**
  120. * @return FormFieldTranslation|null
  121. */
  122. public function getTranslation(string $locale, bool $create = false, bool $fallback = false)
  123. {
  124. foreach ($this->translations as $translation) {
  125. if ($translation->getLocale() == $locale) {
  126. return $translation;
  127. }
  128. }
  129. if ($create) {
  130. $translation = new FormFieldTranslation();
  131. $translation->setLocale($locale);
  132. $this->addTranslation($translation);
  133. $translation->setField($this);
  134. return $translation;
  135. }
  136. if ($fallback) {
  137. return $this->getTranslation($this->getDefaultLocale());
  138. }
  139. return null;
  140. }
  141. public function addTranslation(FormFieldTranslation $translation): self
  142. {
  143. $this->translations[] = $translation;
  144. return $this;
  145. }
  146. public function removeTranslation(FormFieldTranslation $translation): void
  147. {
  148. $this->translations->removeElement($translation);
  149. }
  150. /**
  151. * @return Collection<int, FormFieldTranslation>
  152. */
  153. public function getTranslations()
  154. {
  155. return $this->translations;
  156. }
  157. public function setForm(Form $form): self
  158. {
  159. $this->form = $form;
  160. return $this;
  161. }
  162. public function getForm(): Form
  163. {
  164. return $this->form;
  165. }
  166. }