vendor/se7enxweb/admin-ui/src/lib/Form/Factory/FormFactory.php line 1074

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\AdminUi\Form\Factory;
  8. use Ibexa\AdminUi\Exception\InvalidArgumentException;
  9. use Ibexa\AdminUi\Form\Data\Bookmark\BookmarkRemoveData;
  10. use Ibexa\AdminUi\Form\Data\Content\ContentVisibilityUpdateData;
  11. use Ibexa\AdminUi\Form\Data\Content\CustomUrl\CustomUrlAddData;
  12. use Ibexa\AdminUi\Form\Data\Content\CustomUrl\CustomUrlRemoveData;
  13. use Ibexa\AdminUi\Form\Data\Content\Draft\ContentCreateData;
  14. use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
  15. use Ibexa\AdminUi\Form\Data\Content\Draft\ContentRemoveData;
  16. use Ibexa\AdminUi\Form\Data\Content\Location\ContentLocationAddData;
  17. use Ibexa\AdminUi\Form\Data\Content\Location\ContentLocationRemoveData;
  18. use Ibexa\AdminUi\Form\Data\Content\Location\ContentMainLocationUpdateData;
  19. use Ibexa\AdminUi\Form\Data\Content\Translation\TranslationAddData;
  20. use Ibexa\AdminUi\Form\Data\Content\Translation\TranslationDeleteData;
  21. use Ibexa\AdminUi\Form\Data\ContentType\ContentTypesDeleteData;
  22. use Ibexa\AdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupCreateData;
  23. use Ibexa\AdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupDeleteData;
  24. use Ibexa\AdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupsDeleteData;
  25. use Ibexa\AdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupUpdateData;
  26. use Ibexa\AdminUi\Form\Data\Language\LanguageCreateData;
  27. use Ibexa\AdminUi\Form\Data\Language\LanguageDeleteData;
  28. use Ibexa\AdminUi\Form\Data\Language\LanguagesDeleteData;
  29. use Ibexa\AdminUi\Form\Data\Language\LanguageUpdateData;
  30. use Ibexa\AdminUi\Form\Data\Location\LocationCopyData;
  31. use Ibexa\AdminUi\Form\Data\Location\LocationCopySubtreeData;
  32. use Ibexa\AdminUi\Form\Data\Location\LocationMoveData;
  33. use Ibexa\AdminUi\Form\Data\Location\LocationSwapData;
  34. use Ibexa\AdminUi\Form\Data\Location\LocationTrashData;
  35. use Ibexa\AdminUi\Form\Data\Location\LocationUpdateData;
  36. use Ibexa\AdminUi\Form\Data\Location\LocationUpdateVisibilityData;
  37. use Ibexa\AdminUi\Form\Data\Notification\NotificationSelectionData;
  38. use Ibexa\AdminUi\Form\Data\ObjectState\ObjectStateGroupCreateData;
  39. use Ibexa\AdminUi\Form\Data\ObjectState\ObjectStateGroupDeleteData;
  40. use Ibexa\AdminUi\Form\Data\ObjectState\ObjectStateGroupsDeleteData;
  41. use Ibexa\AdminUi\Form\Data\ObjectState\ObjectStateGroupUpdateData;
  42. use Ibexa\AdminUi\Form\Data\Policy\PoliciesDeleteData;
  43. use Ibexa\AdminUi\Form\Data\Policy\PolicyCreateData;
  44. use Ibexa\AdminUi\Form\Data\Policy\PolicyDeleteData;
  45. use Ibexa\AdminUi\Form\Data\Policy\PolicyUpdateData;
  46. use Ibexa\AdminUi\Form\Data\Role\RoleAssignmentCreateData;
  47. use Ibexa\AdminUi\Form\Data\Role\RoleAssignmentDeleteData;
  48. use Ibexa\AdminUi\Form\Data\Role\RoleAssignmentsDeleteData;
  49. use Ibexa\AdminUi\Form\Data\Role\RoleCreateData;
  50. use Ibexa\AdminUi\Form\Data\Role\RoleDeleteData;
  51. use Ibexa\AdminUi\Form\Data\Role\RolesDeleteData;
  52. use Ibexa\AdminUi\Form\Data\Role\RoleUpdateData;
  53. use Ibexa\AdminUi\Form\Data\Section\SectionContentAssignData;
  54. use Ibexa\AdminUi\Form\Data\Section\SectionCreateData;
  55. use Ibexa\AdminUi\Form\Data\Section\SectionDeleteData;
  56. use Ibexa\AdminUi\Form\Data\Section\SectionsDeleteData;
  57. use Ibexa\AdminUi\Form\Data\Section\SectionUpdateData;
  58. use Ibexa\AdminUi\Form\Data\URL\URLListData;
  59. use Ibexa\AdminUi\Form\Data\URL\URLUpdateData;
  60. use Ibexa\AdminUi\Form\Data\URLWildcard\URLWildcardData;
  61. use Ibexa\AdminUi\Form\Data\URLWildcard\URLWildcardDeleteData;
  62. use Ibexa\AdminUi\Form\Data\URLWildcard\URLWildcardUpdateData;
  63. use Ibexa\AdminUi\Form\Data\User\UserDeleteData;
  64. use Ibexa\AdminUi\Form\Data\User\UserEditData;
  65. use Ibexa\AdminUi\Form\Data\Version\VersionRemoveData;
  66. use Ibexa\AdminUi\Form\Type\Bookmark\BookmarkRemoveType;
  67. use Ibexa\AdminUi\Form\Type\Content\ContentVisibilityUpdateType;
  68. use Ibexa\AdminUi\Form\Type\Content\CustomUrl\CustomUrlAddType;
  69. use Ibexa\AdminUi\Form\Type\Content\CustomUrl\CustomUrlRemoveType;
  70. use Ibexa\AdminUi\Form\Type\Content\Draft\ContentCreateType;
  71. use Ibexa\AdminUi\Form\Type\Content\Draft\ContentEditType;
  72. use Ibexa\AdminUi\Form\Type\Content\Draft\ContentRemoveType;
  73. use Ibexa\AdminUi\Form\Type\Content\Location\ContentLocationAddType;
  74. use Ibexa\AdminUi\Form\Type\Content\Location\ContentLocationRemoveType;
  75. use Ibexa\AdminUi\Form\Type\Content\Location\ContentMainLocationUpdateType;
  76. use Ibexa\AdminUi\Form\Type\Content\Translation\TranslationAddType;
  77. use Ibexa\AdminUi\Form\Type\Content\Translation\TranslationDeleteType;
  78. use Ibexa\AdminUi\Form\Type\ContentType\ContentTypesDeleteType;
  79. use Ibexa\AdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupCreateType;
  80. use Ibexa\AdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupDeleteType;
  81. use Ibexa\AdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupsDeleteType;
  82. use Ibexa\AdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupUpdateType;
  83. use Ibexa\AdminUi\Form\Type\Language\LanguageCreateType;
  84. use Ibexa\AdminUi\Form\Type\Language\LanguageDeleteType;
  85. use Ibexa\AdminUi\Form\Type\Language\LanguagesDeleteType;
  86. use Ibexa\AdminUi\Form\Type\Language\LanguageUpdateType;
  87. use Ibexa\AdminUi\Form\Type\Location\LocationCopySubtreeType;
  88. use Ibexa\AdminUi\Form\Type\Location\LocationCopyType;
  89. use Ibexa\AdminUi\Form\Type\Location\LocationMoveType;
  90. use Ibexa\AdminUi\Form\Type\Location\LocationSwapType;
  91. use Ibexa\AdminUi\Form\Type\Location\LocationTrashType;
  92. use Ibexa\AdminUi\Form\Type\Location\LocationUpdateType;
  93. use Ibexa\AdminUi\Form\Type\Location\LocationUpdateVisibilityType;
  94. use Ibexa\AdminUi\Form\Type\Notification\NotificationSelectionType;
  95. use Ibexa\AdminUi\Form\Type\ObjectState\ObjectStateGroupCreateType;
  96. use Ibexa\AdminUi\Form\Type\ObjectState\ObjectStateGroupDeleteType;
  97. use Ibexa\AdminUi\Form\Type\ObjectState\ObjectStateGroupsDeleteType;
  98. use Ibexa\AdminUi\Form\Type\ObjectState\ObjectStateGroupUpdateType;
  99. use Ibexa\AdminUi\Form\Type\Policy\PoliciesDeleteType;
  100. use Ibexa\AdminUi\Form\Type\Policy\PolicyCreateType;
  101. use Ibexa\AdminUi\Form\Type\Policy\PolicyCreateWithLimitationType;
  102. use Ibexa\AdminUi\Form\Type\Policy\PolicyDeleteType;
  103. use Ibexa\AdminUi\Form\Type\Policy\PolicyUpdateType;
  104. use Ibexa\AdminUi\Form\Type\Role\RoleAssignmentCreateType;
  105. use Ibexa\AdminUi\Form\Type\Role\RoleAssignmentDeleteType;
  106. use Ibexa\AdminUi\Form\Type\Role\RoleAssignmentsDeleteType;
  107. use Ibexa\AdminUi\Form\Type\Role\RoleCreateType;
  108. use Ibexa\AdminUi\Form\Type\Role\RoleDeleteType;
  109. use Ibexa\AdminUi\Form\Type\Role\RolesDeleteType;
  110. use Ibexa\AdminUi\Form\Type\Role\RoleUpdateType;
  111. use Ibexa\AdminUi\Form\Type\Search\SearchType;
  112. use Ibexa\AdminUi\Form\Type\Section\SectionContentAssignType;
  113. use Ibexa\AdminUi\Form\Type\Section\SectionCreateType;
  114. use Ibexa\AdminUi\Form\Type\Section\SectionDeleteType;
  115. use Ibexa\AdminUi\Form\Type\Section\SectionsDeleteType;
  116. use Ibexa\AdminUi\Form\Type\Section\SectionUpdateType;
  117. use Ibexa\AdminUi\Form\Type\URL\URLEditType;
  118. use Ibexa\AdminUi\Form\Type\URL\URLListType;
  119. use Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardDeleteType;
  120. use Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardType;
  121. use Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardUpdateType;
  122. use Ibexa\AdminUi\Form\Type\User\UserDeleteType;
  123. use Ibexa\AdminUi\Form\Type\User\UserEditType;
  124. use Ibexa\AdminUi\Form\Type\Version\VersionRemoveType;
  125. use Ibexa\Bundle\Search\Form\Data\SearchData;
  126. use function is_string;
  127. use Symfony\Component\Form\FormFactoryInterface;
  128. use Symfony\Component\Form\FormInterface;
  129. use Symfony\Component\Form\Util\StringUtil;
  130. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  131. use Symfony\Contracts\Translation\TranslatorInterface;
  132. class FormFactory
  133. {
  134. private FormFactoryInterface $formFactory;
  135. protected UrlGeneratorInterface $urlGenerator;
  136. private TranslatorInterface $translator;
  137. public function __construct(
  138. FormFactoryInterface $formFactory,
  139. UrlGeneratorInterface $urlGenerator,
  140. TranslatorInterface $translator
  141. ) {
  142. $this->formFactory = $formFactory;
  143. $this->urlGenerator = $urlGenerator;
  144. $this->translator = $translator;
  145. }
  146. /**
  147. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  148. */
  149. public function contentEdit(
  150. ?ContentEditData $data = null,
  151. ?string $name = null,
  152. array $options = []
  153. ): FormInterface {
  154. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentEditType::class);
  155. if (!is_string($name) || $name === '') {
  156. throw new InvalidArgumentException(
  157. 'name',
  158. 'The form name must be a non-empty string.'
  159. );
  160. }
  161. $data = $data ?? new ContentEditData();
  162. if (empty($options['language_codes']) && null !== $data->getVersionInfo()) {
  163. $options['language_codes'] = $data->getVersionInfo()->languageCodes;
  164. }
  165. return $this->formFactory->createNamed(
  166. $name,
  167. ContentEditType::class,
  168. $data,
  169. $options
  170. );
  171. }
  172. /**
  173. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  174. */
  175. public function createContent(
  176. ?ContentCreateData $data = null,
  177. ?string $name = null
  178. ): FormInterface {
  179. $data = $data ?? new ContentCreateData();
  180. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentCreateType::class);
  181. if (!is_string($name) || $name === '') {
  182. throw new InvalidArgumentException(
  183. 'name',
  184. 'The form name must be a non-empty string.'
  185. );
  186. }
  187. return $this->formFactory->createNamed($name, ContentCreateType::class, $data);
  188. }
  189. /**
  190. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  191. */
  192. public function deleteContentTypes(
  193. ?ContentTypesDeleteData $data = null,
  194. ?string $name = null
  195. ): FormInterface {
  196. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentTypesDeleteType::class);
  197. if (!is_string($name) || $name === '') {
  198. throw new InvalidArgumentException(
  199. 'name',
  200. 'The form name must be a non-empty string.'
  201. );
  202. }
  203. return $this->formFactory->createNamed($name, ContentTypesDeleteType::class, $data);
  204. }
  205. public function createContentTypeGroup(
  206. ?ContentTypeGroupCreateData $data = null,
  207. ?string $name = null
  208. ): FormInterface {
  209. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentTypeGroupCreateType::class);
  210. if (!is_string($name) || $name === '') {
  211. throw new InvalidArgumentException(
  212. 'name',
  213. 'The form name must be a non-empty string.'
  214. );
  215. }
  216. return $this->formFactory->createNamed(
  217. $name,
  218. ContentTypeGroupCreateType::class,
  219. $data ?? new ContentTypeGroupCreateData()
  220. );
  221. }
  222. public function updateContentTypeGroup(
  223. ?ContentTypeGroupUpdateData $data = null,
  224. ?string $name = null
  225. ): FormInterface {
  226. if ($name === null && $data === null) {
  227. throw new \InvalidArgumentException('Either $name or $data must be provided.');
  228. }
  229. $name = $name ?: sprintf('update-content-type-group-%d', $data->getContentTypeGroup()->id);
  230. return $this->formFactory->createNamed($name, ContentTypeGroupUpdateType::class, $data);
  231. }
  232. public function deleteContentTypeGroup(
  233. ?ContentTypeGroupDeleteData $data = null,
  234. ?string $name = null
  235. ): FormInterface {
  236. if ($name === null && $data === null) {
  237. throw new \InvalidArgumentException('Either $name or $data must be provided.');
  238. }
  239. $name = $name ?: sprintf('delete-content-type-group-%d', $data->getContentTypeGroup()->id);
  240. return $this->formFactory->createNamed($name, ContentTypeGroupDeleteType::class, $data);
  241. }
  242. /**
  243. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  244. */
  245. public function deleteContentTypeGroups(
  246. ?ContentTypeGroupsDeleteData $data = null,
  247. ?string $name = null
  248. ): FormInterface {
  249. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentTypeGroupsDeleteType::class);
  250. if (!is_string($name) || $name === '') {
  251. throw new InvalidArgumentException(
  252. 'name',
  253. 'The form name must be a non-empty string.'
  254. );
  255. }
  256. return $this->formFactory->createNamed($name, ContentTypeGroupsDeleteType::class, $data);
  257. }
  258. /**
  259. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  260. */
  261. public function addTranslation(
  262. ?TranslationAddData $data = null,
  263. ?string $name = null
  264. ): FormInterface {
  265. $name = $name ?: sprintf('add-translation');
  266. return $this->formFactory->createNamed($name, TranslationAddType::class, $data ?? new TranslationAddData());
  267. }
  268. /**
  269. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  270. */
  271. public function deleteTranslation(
  272. ?TranslationDeleteData $data = null,
  273. ?string $name = null
  274. ): FormInterface {
  275. $name = $name ?: sprintf('delete-translations');
  276. return $this->formFactory->createNamed($name, TranslationDeleteType::class, $data);
  277. }
  278. /**
  279. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  280. */
  281. public function removeVersion(
  282. ?VersionRemoveData $data = null,
  283. ?string $name = null
  284. ): FormInterface {
  285. $name = $name ?: StringUtil::fqcnToBlockPrefix(VersionRemoveType::class);
  286. if (!is_string($name) || $name === '') {
  287. throw new InvalidArgumentException(
  288. 'name',
  289. 'The form name must be a non-empty string.'
  290. );
  291. }
  292. return $this->formFactory->createNamed($name, VersionRemoveType::class, $data);
  293. }
  294. public function addLocation(
  295. ?ContentLocationAddData $data = null,
  296. ?string $name = null
  297. ): FormInterface {
  298. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentLocationAddType::class);
  299. if (!is_string($name) || $name === '') {
  300. throw new InvalidArgumentException(
  301. 'name',
  302. 'The form name must be a non-empty string.'
  303. );
  304. }
  305. return $this->formFactory->createNamed($name, ContentLocationAddType::class, $data);
  306. }
  307. public function removeLocation(
  308. ?ContentLocationRemoveData $data = null,
  309. ?string $name = null
  310. ): FormInterface {
  311. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentLocationRemoveType::class);
  312. if (!is_string($name) || $name === '') {
  313. throw new InvalidArgumentException(
  314. 'name',
  315. 'The form name must be a non-empty string.'
  316. );
  317. }
  318. return $this->formFactory->createNamed($name, ContentLocationRemoveType::class, $data);
  319. }
  320. public function swapLocation(
  321. ?LocationSwapData $data = null,
  322. ?string $name = null
  323. ): FormInterface {
  324. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationSwapType::class);
  325. if (!is_string($name) || $name === '') {
  326. throw new InvalidArgumentException(
  327. 'name',
  328. 'The form name must be a non-empty string.'
  329. );
  330. }
  331. return $this->formFactory->createNamed($name, LocationSwapType::class, $data);
  332. }
  333. /**
  334. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  335. */
  336. public function updateContentMainLocation(
  337. ?ContentMainLocationUpdateData $data = null,
  338. ?string $name = null
  339. ): FormInterface {
  340. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentMainLocationUpdateType::class);
  341. if (!is_string($name) || $name === '') {
  342. throw new InvalidArgumentException(
  343. 'name',
  344. 'The form name must be a non-empty string.'
  345. );
  346. }
  347. $data = $data ?? new ContentMainLocationUpdateData();
  348. return $this->formFactory->createNamed(
  349. $name,
  350. ContentMainLocationUpdateType::class,
  351. $data
  352. );
  353. }
  354. public function trashLocation(
  355. ?LocationTrashData $data = null,
  356. ?string $name = null
  357. ): FormInterface {
  358. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationTrashType::class);
  359. if (!is_string($name) || $name === '') {
  360. throw new InvalidArgumentException(
  361. 'name',
  362. 'The form name must be a non-empty string.'
  363. );
  364. }
  365. $data = $data ?? new LocationTrashData();
  366. return $this->formFactory->createNamed($name, LocationTrashType::class, $data);
  367. }
  368. public function moveLocation(
  369. ?LocationMoveData $data = null,
  370. ?string $name = null
  371. ): FormInterface {
  372. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationMoveType::class);
  373. if (!is_string($name) || $name === '') {
  374. throw new InvalidArgumentException(
  375. 'name',
  376. 'The form name must be a non-empty string.'
  377. );
  378. }
  379. return $this->formFactory->createNamed($name, LocationMoveType::class, $data);
  380. }
  381. public function copyLocation(
  382. ?LocationCopyData $data = null,
  383. ?string $name = null
  384. ): FormInterface {
  385. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationCopyType::class);
  386. if (!is_string($name) || $name === '') {
  387. throw new InvalidArgumentException(
  388. 'name',
  389. 'The form name must be a non-empty string.'
  390. );
  391. }
  392. return $this->formFactory->createNamed($name, LocationCopyType::class, $data);
  393. }
  394. /**
  395. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  396. */
  397. public function updateVisibilityLocation(
  398. ?LocationUpdateVisibilityData $data = null,
  399. ?string $name = null
  400. ): FormInterface {
  401. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationUpdateVisibilityData::class);
  402. if (!is_string($name) || $name === '') {
  403. throw new InvalidArgumentException(
  404. 'name',
  405. 'The form name must be a non-empty string.'
  406. );
  407. }
  408. return $this->formFactory->createNamed($name, LocationUpdateVisibilityType::class, $data);
  409. }
  410. /**
  411. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  412. */
  413. public function updateVisibilityContent(
  414. ?ContentVisibilityUpdateData $data = null,
  415. ?string $name = null
  416. ): FormInterface {
  417. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentVisibilityUpdateType::class);
  418. if (!is_string($name) || $name === '') {
  419. throw new InvalidArgumentException(
  420. 'name',
  421. 'The form name must be a non-empty string.'
  422. );
  423. }
  424. $data = $data ?? new ContentVisibilityUpdateData();
  425. return $this->formFactory->createNamed($name, ContentVisibilityUpdateType::class, $data);
  426. }
  427. public function updateLocation(
  428. ?LocationUpdateData $data = null,
  429. ?string $name = null
  430. ): FormInterface {
  431. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationUpdateType::class);
  432. if (!is_string($name) || $name === '') {
  433. throw new InvalidArgumentException(
  434. 'name',
  435. 'The form name must be a non-empty string.'
  436. );
  437. }
  438. return $this->formFactory->createNamed($name, LocationUpdateType::class, $data);
  439. }
  440. public function assignContentSectionForm(
  441. ?SectionContentAssignData $data = null,
  442. ?string $name = null
  443. ): FormInterface {
  444. $name = $name ?: StringUtil::fqcnToBlockPrefix(SectionContentAssignType::class);
  445. if (!is_string($name) || $name === '') {
  446. throw new InvalidArgumentException(
  447. 'name',
  448. 'The form name must be a non-empty string.'
  449. );
  450. }
  451. return $this->formFactory->createNamed($name, SectionContentAssignType::class, $data);
  452. }
  453. public function deleteSection(
  454. ?SectionDeleteData $data = null,
  455. ?string $name = null
  456. ): FormInterface {
  457. if ($name !== null) {
  458. return $this->formFactory->createNamed($name, SectionDeleteType::class, $data);
  459. }
  460. if ($data === null || $data->getSection() === null) {
  461. throw new \InvalidArgumentException(
  462. 'SectionDeleteData with Section must be provided when $name is not set.'
  463. );
  464. }
  465. $name = sprintf('delete-section-%d', $data->getSection()->id);
  466. return $this->formFactory->createNamed($name, SectionDeleteType::class, $data);
  467. }
  468. /**
  469. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  470. */
  471. public function deleteSections(
  472. ?SectionsDeleteData $data = null,
  473. ?string $name = null
  474. ): FormInterface {
  475. $name = $name ?: StringUtil::fqcnToBlockPrefix(SectionsDeleteType::class);
  476. if (!is_string($name) || $name === '') {
  477. throw new InvalidArgumentException(
  478. 'name',
  479. 'The form name must be a non-empty string.'
  480. );
  481. }
  482. return $this->formFactory->createNamed($name, SectionsDeleteType::class, $data);
  483. }
  484. public function createSection(
  485. ?SectionCreateData $data = null,
  486. ?string $name = null
  487. ): FormInterface {
  488. $name = $name ?: StringUtil::fqcnToBlockPrefix(SectionCreateType::class);
  489. if (!is_string($name) || $name === '') {
  490. throw new InvalidArgumentException(
  491. 'name',
  492. 'The form name must be a non-empty string.'
  493. );
  494. }
  495. return $this->formFactory->createNamed(
  496. $name,
  497. SectionCreateType::class,
  498. $data ?? new SectionCreateData()
  499. );
  500. }
  501. public function updateSection(
  502. ?SectionUpdateData $data = null,
  503. ?string $name = null
  504. ): FormInterface {
  505. if ($name !== null) {
  506. return $this->formFactory->createNamed($name, SectionUpdateType::class, $data);
  507. }
  508. if ($data === null || $data->getSection() === null) {
  509. throw new \InvalidArgumentException(
  510. 'SectionUpdateData with Section must be provided when $name is not set.'
  511. );
  512. }
  513. $name = sprintf('update-section-%d', $data->getSection()->id);
  514. return $this->formFactory->createNamed($name, SectionUpdateType::class, $data);
  515. }
  516. public function createLanguage(
  517. ?LanguageCreateData $data = null,
  518. ?string $name = null
  519. ): FormInterface {
  520. $name = $name ?: StringUtil::fqcnToBlockPrefix(LanguageCreateType::class);
  521. if (!is_string($name) || $name === '') {
  522. throw new InvalidArgumentException(
  523. 'name',
  524. 'The form name must be a non-empty string.'
  525. );
  526. }
  527. return $this->formFactory->createNamed(
  528. $name,
  529. LanguageCreateType::class,
  530. $data ?? new LanguageCreateData()
  531. );
  532. }
  533. public function updateLanguage(
  534. LanguageUpdateData $data,
  535. ?string $name = null
  536. ): FormInterface {
  537. $name = $name ?: sprintf('update-language-%d', $data->getLanguage()->id);
  538. return $this->formFactory->createNamed($name, LanguageUpdateType::class, $data);
  539. }
  540. public function deleteLanguage(
  541. LanguageDeleteData $data,
  542. ?string $name = null
  543. ): FormInterface {
  544. if ($name === null) {
  545. $language = $data->getLanguage();
  546. if ($language === null) {
  547. throw new \InvalidArgumentException('Language is not provided in LanguageDeleteData.');
  548. }
  549. $name = sprintf('delete-language-%d', $language->id);
  550. }
  551. return $this->formFactory->createNamed($name, LanguageDeleteType::class, $data);
  552. }
  553. /**
  554. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  555. */
  556. public function deleteLanguages(
  557. ?LanguagesDeleteData $data = null,
  558. ?string $name = null
  559. ): FormInterface {
  560. $name = $name ?: StringUtil::fqcnToBlockPrefix(LanguagesDeleteType::class);
  561. if (!is_string($name) || $name === '') {
  562. throw new InvalidArgumentException(
  563. 'name',
  564. 'The form name must be a non-empty string.'
  565. );
  566. }
  567. return $this->formFactory->createNamed($name, LanguagesDeleteType::class, $data);
  568. }
  569. public function createRole(
  570. ?RoleCreateData $data = null,
  571. ?string $name = null
  572. ): FormInterface {
  573. $name = $name ?: StringUtil::fqcnToBlockPrefix(RoleCreateType::class);
  574. if (!is_string($name) || $name === '') {
  575. throw new InvalidArgumentException(
  576. 'name',
  577. 'The form name must be a non-empty string.'
  578. );
  579. }
  580. return $this->formFactory->createNamed($name, RoleCreateType::class, $data);
  581. }
  582. public function updateRole(
  583. RoleUpdateData $data,
  584. ?string $name = null
  585. ): FormInterface {
  586. $name = $name ?: sprintf('update-role-%d', $data->getRole()->id);
  587. return $this->formFactory->createNamed($name, RoleUpdateType::class, $data);
  588. }
  589. public function deleteRole(
  590. RoleDeleteData $data,
  591. ?string $name = null
  592. ): FormInterface {
  593. $name = $name ?: sprintf('delete-role-%d', $data->getRole()->id);
  594. return $this->formFactory->createNamed($name, RoleDeleteType::class, $data);
  595. }
  596. /**
  597. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  598. */
  599. public function deleteRoles(
  600. ?RolesDeleteData $data = null,
  601. ?string $name = null
  602. ): FormInterface {
  603. $name = $name ?: sprintf('delete-roles');
  604. return $this->formFactory->createNamed($name, RolesDeleteType::class, $data);
  605. }
  606. public function createRoleAssignment(
  607. ?RoleAssignmentCreateData $data = null,
  608. ?string $name = null
  609. ): FormInterface {
  610. $name = $name ?: StringUtil::fqcnToBlockPrefix(RoleAssignmentCreateType::class);
  611. if (!is_string($name) || $name === '') {
  612. throw new InvalidArgumentException(
  613. 'name',
  614. 'The form name must be a non-empty string.'
  615. );
  616. }
  617. return $this->formFactory->createNamed(
  618. $name,
  619. RoleAssignmentCreateType::class,
  620. $data ?? new RoleAssignmentCreateData()
  621. );
  622. }
  623. public function deleteRoleAssignment(
  624. RoleAssignmentDeleteData $data,
  625. ?string $name = null
  626. ): FormInterface {
  627. $role = $data->getRoleAssignment()->getRole()->id;
  628. $limitation = !empty($data->getRoleAssignment()->getRoleLimitation())
  629. ? $data->getRoleAssignment()->getRoleLimitation()->getIdentifier()
  630. : 'none';
  631. $name = $name ?: sprintf(
  632. 'delete-role-assignment-%s',
  633. hash('sha256', implode('/', [$role, $limitation]))
  634. );
  635. return $this->formFactory->createNamed($name, RoleAssignmentDeleteType::class, $data);
  636. }
  637. public function deleteRoleAssignments(
  638. ?RoleAssignmentsDeleteData $data = null,
  639. ?string $name = null
  640. ): FormInterface {
  641. $name = $name ?: StringUtil::fqcnToBlockPrefix(RoleAssignmentsDeleteType::class);
  642. if (!is_string($name) || $name === '') {
  643. throw new InvalidArgumentException(
  644. 'name',
  645. 'The form name must be a non-empty string.'
  646. );
  647. }
  648. return $this->formFactory->createNamed($name, RoleAssignmentsDeleteType::class, $data);
  649. }
  650. public function createPolicy(
  651. ?PolicyCreateData $data = null,
  652. ?string $name = null
  653. ): FormInterface {
  654. $name = $name ?: StringUtil::fqcnToBlockPrefix(PolicyCreateType::class);
  655. if (!is_string($name) || $name === '') {
  656. throw new InvalidArgumentException(
  657. 'name',
  658. 'The form name must be a non-empty string.'
  659. );
  660. }
  661. return $this->formFactory->createNamed($name, PolicyCreateType::class, $data);
  662. }
  663. public function createPolicyWithLimitation(
  664. ?PolicyCreateData $data = null,
  665. ?string $name = null
  666. ): FormInterface {
  667. $name = $name ?: StringUtil::fqcnToBlockPrefix(PolicyCreateWithLimitationType::class);
  668. if (!is_string($name) || $name === '') {
  669. throw new InvalidArgumentException(
  670. 'name',
  671. 'The form name must be a non-empty string.'
  672. );
  673. }
  674. return $this->formFactory->createNamed($name, PolicyCreateWithLimitationType::class, $data);
  675. }
  676. public function updatePolicy(
  677. PolicyUpdateData $data,
  678. ?string $name = null
  679. ): FormInterface {
  680. $name = $name ?: sprintf(
  681. 'update-policy-%s',
  682. hash('sha256', implode('/', $data->getPolicy() ?? []))
  683. );
  684. return $this->formFactory->createNamed($name, PolicyUpdateType::class, $data);
  685. }
  686. public function deletePolicy(
  687. PolicyDeleteData $data,
  688. ?string $name = null
  689. ): FormInterface {
  690. $name = $name ?: sprintf(
  691. 'delete-policy-%s',
  692. hash('sha256', implode('/', $data->getPolicy() ?? []))
  693. );
  694. return $this->formFactory->createNamed($name, PolicyDeleteType::class, $data);
  695. }
  696. /**
  697. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  698. */
  699. public function deletePolicies(
  700. ?PoliciesDeleteData $data = null,
  701. ?string $name = null
  702. ): FormInterface {
  703. $name = $name ?: StringUtil::fqcnToBlockPrefix(PoliciesDeleteType::class);
  704. if (!is_string($name) || $name === '') {
  705. throw new InvalidArgumentException(
  706. 'name',
  707. 'The form name must be a non-empty string.'
  708. );
  709. }
  710. return $this->formFactory->createNamed($name, PoliciesDeleteType::class, $data);
  711. }
  712. public function createSearchForm(
  713. ?SearchData $data = null,
  714. ?string $name = null,
  715. array $options = []
  716. ): FormInterface {
  717. $name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
  718. if (!is_string($name) || $name === '') {
  719. throw new InvalidArgumentException(
  720. 'name',
  721. 'The form name must be a non-empty string.'
  722. );
  723. }
  724. return $this->formFactory->createNamed($name, SearchType::class, $data, $options);
  725. }
  726. public function createUrlListForm(
  727. ?URLListData $data = null,
  728. ?string $name = null,
  729. array $options = []
  730. ): FormInterface {
  731. $name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
  732. if (!is_string($name) || $name === '') {
  733. throw new InvalidArgumentException(
  734. 'name',
  735. 'The form name must be a non-empty string.'
  736. );
  737. }
  738. return $this->formFactory->createNamed($name, URLListType::class, $data, $options);
  739. }
  740. public function createUrlEditForm(
  741. ?URLUpdateData $data = null,
  742. ?string $name = null,
  743. array $options = []
  744. ): FormInterface {
  745. $name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
  746. if (!is_string($name) || $name === '') {
  747. throw new InvalidArgumentException(
  748. 'name',
  749. 'The form name must be a non-empty string.'
  750. );
  751. }
  752. return $this->formFactory->createNamed($name, URLEditType::class, $data, $options);
  753. }
  754. public function deleteUser(
  755. ?UserDeleteData $data = null,
  756. ?string $name = null
  757. ): FormInterface {
  758. $name = $name ?: StringUtil::fqcnToBlockPrefix(UserDeleteType::class);
  759. if (!is_string($name) || $name === '') {
  760. throw new InvalidArgumentException(
  761. 'name',
  762. 'The form name must be a non-empty string.'
  763. );
  764. }
  765. return $this->formFactory->createNamed($name, UserDeleteType::class, $data);
  766. }
  767. public function addCustomUrl(
  768. ?CustomUrlAddData $data = null,
  769. ?string $name = null
  770. ): FormInterface {
  771. $name = $name ?: StringUtil::fqcnToBlockPrefix(CustomUrlAddType::class);
  772. if (!is_string($name) || $name === '') {
  773. throw new InvalidArgumentException(
  774. 'name',
  775. 'The form name must be a non-empty string.'
  776. );
  777. }
  778. return $this->formFactory->createNamed($name, CustomUrlAddType::class, $data ?? new CustomUrlAddData());
  779. }
  780. public function removeCustomUrl(
  781. ?CustomUrlRemoveData $data = null,
  782. ?string $name = null
  783. ): FormInterface {
  784. $name = $name ?: StringUtil::fqcnToBlockPrefix(CustomUrlRemoveType::class);
  785. if (!is_string($name) || $name === '') {
  786. throw new InvalidArgumentException(
  787. 'name',
  788. 'The form name must be a non-empty string.'
  789. );
  790. }
  791. return $this->formFactory->createNamed($name, CustomUrlRemoveType::class, $data ?? new CustomUrlRemoveData());
  792. }
  793. public function createObjectStateGroup(
  794. ?ObjectStateGroupCreateData $data = null,
  795. ?string $name = null
  796. ): FormInterface {
  797. $name = $name ?: StringUtil::fqcnToBlockPrefix(ObjectStateGroupCreateType::class);
  798. if (!is_string($name) || $name === '') {
  799. throw new InvalidArgumentException(
  800. 'name',
  801. 'The form name must be a non-empty string.'
  802. );
  803. }
  804. return $this->formFactory->createNamed(
  805. $name,
  806. ObjectStateGroupCreateType::class,
  807. $data ?? new ObjectStateGroupCreateData()
  808. );
  809. }
  810. public function deleteObjectStateGroup(
  811. ?ObjectStateGroupDeleteData $data = null,
  812. ?string $name = null
  813. ): FormInterface {
  814. if ($name === null && $data === null) {
  815. throw new \InvalidArgumentException('Either $name or $data must be provided.');
  816. }
  817. $name = $name ?: sprintf('delete-object-state-group-%d', $data->getObjectStateGroup()->id);
  818. return $this->formFactory->createNamed($name, ObjectStateGroupDeleteType::class, $data);
  819. }
  820. /**
  821. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  822. */
  823. public function deleteObjectStateGroups(
  824. ?ObjectStateGroupsDeleteData $data = null,
  825. ?string $name = null
  826. ): FormInterface {
  827. $name = $name ?: StringUtil::fqcnToBlockPrefix(ObjectStateGroupsDeleteType::class);
  828. if (!is_string($name) || $name === '') {
  829. throw new InvalidArgumentException(
  830. 'name',
  831. 'The form name must be a non-empty string.'
  832. );
  833. }
  834. return $this->formFactory->createNamed($name, ObjectStateGroupsDeleteType::class, $data);
  835. }
  836. public function updateObjectStateGroup(
  837. ?ObjectStateGroupUpdateData $data = null,
  838. ?string $name = null
  839. ): FormInterface {
  840. if ($name === null && $data === null) {
  841. throw new \InvalidArgumentException('Either $name or $data must be provided.');
  842. }
  843. $name = $name ?: sprintf('update-object-state-group-%d', $data->getObjectStateGroup()->id);
  844. return $this->formFactory->createNamed($name, ObjectStateGroupUpdateType::class, $data);
  845. }
  846. public function copyLocationSubtree(
  847. ?LocationCopySubtreeData $data = null,
  848. ?string $name = null
  849. ): FormInterface {
  850. $name = $name ?: StringUtil::fqcnToBlockPrefix(LocationCopySubtreeType::class);
  851. if (!is_string($name) || $name === '') {
  852. throw new InvalidArgumentException(
  853. 'name',
  854. 'The form name must be a non-empty string.'
  855. );
  856. }
  857. return $this->formFactory->createNamed($name, LocationCopySubtreeType::class, $data);
  858. }
  859. public function removeBookmark(
  860. ?BookmarkRemoveData $data = null,
  861. ?string $name = null
  862. ): FormInterface {
  863. $name = $name ?: StringUtil::fqcnToBlockPrefix(BookmarkRemoveType::class);
  864. if (!is_string($name) || $name === '') {
  865. throw new InvalidArgumentException(
  866. 'name',
  867. 'The form name must be a non-empty string.'
  868. );
  869. }
  870. return $this->formFactory->createNamed($name, BookmarkRemoveType::class, $data);
  871. }
  872. public function editUser(
  873. ?UserEditData $data = null,
  874. ?string $name = null
  875. ): FormInterface {
  876. $name = $name ?: StringUtil::fqcnToBlockPrefix(UserEditType::class);
  877. if (!is_string($name) || $name === '') {
  878. throw new InvalidArgumentException(
  879. 'name',
  880. 'The form name must be a non-empty string.'
  881. );
  882. }
  883. $data = $data ?? new UserEditData();
  884. $options = null !== $data->getVersionInfo()
  885. ? ['language_codes' => $data->getVersionInfo()->languageCodes]
  886. : [];
  887. return $this->formFactory->createNamed($name, UserEditType::class, $data, $options);
  888. }
  889. public function removeContentDraft(
  890. ?ContentRemoveData $data = null,
  891. ?string $name = null
  892. ): FormInterface {
  893. $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentRemoveType::class);
  894. if (!is_string($name) || $name === '') {
  895. throw new InvalidArgumentException(
  896. 'name',
  897. 'The form name must be a non-empty string.'
  898. );
  899. }
  900. return $this->formFactory->createNamed($name, ContentRemoveType::class, $data);
  901. }
  902. /**
  903. * @return \Symfony\Component\Form\FormInterface<\Ibexa\AdminUi\Form\Data\Notification\NotificationSelectionData|null>
  904. */
  905. public function deleteNotification(
  906. NotificationSelectionData $data = null,
  907. ?string $name = null
  908. ): FormInterface {
  909. $name = $name ?: StringUtil::fqcnToBlockPrefix(NotificationSelectionType::class);
  910. if (!is_string($name) || $name === '') {
  911. throw new InvalidArgumentException(
  912. 'name',
  913. 'The form name must be a non-empty string.'
  914. );
  915. }
  916. return $this->formFactory->createNamed(
  917. $name,
  918. NotificationSelectionType::class,
  919. $data
  920. );
  921. }
  922. /**
  923. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  924. */
  925. public function createURLWildcard(
  926. ?URLWildcardData $data = null,
  927. ?string $name = null
  928. ): FormInterface {
  929. $name = $name ?: StringUtil::fqcnToBlockPrefix(URLWildcardType::class);
  930. if (!is_string($name) || $name === '') {
  931. throw new InvalidArgumentException(
  932. 'name',
  933. 'The form name must be a non-empty string.'
  934. );
  935. }
  936. return $this->formFactory->createNamed(
  937. $name,
  938. URLWildcardType::class,
  939. $data ?? new URLWildcardData()
  940. );
  941. }
  942. /**
  943. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  944. */
  945. public function createURLWildcardUpdate(
  946. ?URLWildcardUpdateData $data = null,
  947. ?string $name = null
  948. ): FormInterface {
  949. $name = $name ?: StringUtil::fqcnToBlockPrefix(URLWildcardUpdateType::class);
  950. if (!is_string($name) || $name === '') {
  951. throw new InvalidArgumentException(
  952. 'name',
  953. 'The form name must be a non-empty string.'
  954. );
  955. }
  956. return $this->formFactory->createNamed(
  957. $name,
  958. URLWildcardUpdateType::class,
  959. $data ?? new URLWildcardUpdateData()
  960. );
  961. }
  962. /**
  963. * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
  964. */
  965. public function deleteURLWildcard(
  966. ?URLWildcardDeleteData $data = null,
  967. ?string $name = null
  968. ): FormInterface {
  969. $name = $name ?: StringUtil::fqcnToBlockPrefix(URLWildcardDeleteType::class);
  970. if (!is_string($name) || $name === '') {
  971. throw new InvalidArgumentException(
  972. 'name',
  973. 'The form name must be a non-empty string.'
  974. );
  975. }
  976. return $this->formFactory->createNamed(
  977. $name,
  978. URLWildcardDeleteType::class,
  979. $data ?? new URLWildcardDeleteData()
  980. );
  981. }
  982. }
  983. class_alias(FormFactory::class, 'EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory');