vendor/easycorp/easyadmin-bundle/src/Dto/CrudDto.php line 157

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Dto;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  6. /**
  7. * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  8. */
  9. final class CrudDto
  10. {
  11. private $controllerFqcn;
  12. private $pageName;
  13. private $actionName;
  14. /** @var ActionConfigDto */
  15. private $actionConfigDto;
  16. private $filters;
  17. private $entityFqcn;
  18. private $entityLabelInSingular;
  19. private $entityLabelInPlural;
  20. private $defaultPageTitles = [
  21. Crud::PAGE_DETAIL => 'page_title.detail',
  22. Crud::PAGE_EDIT => 'page_title.edit',
  23. Crud::PAGE_INDEX => 'page_title.index',
  24. Crud::PAGE_NEW => 'page_title.new',
  25. ];
  26. private $customPageTitles;
  27. private $helpMessages;
  28. private $datePattern;
  29. private $timePattern;
  30. private $dateTimePattern;
  31. private $dateIntervalFormat;
  32. private $timezone;
  33. private $numberFormat;
  34. private $defaultSort;
  35. private $searchFields;
  36. private $showEntityActionsAsDropdown;
  37. /** @var PaginatorDto */
  38. private $paginatorDto;
  39. private $overriddenTemplates;
  40. private $formThemes;
  41. private $newFormOptions;
  42. private $editFormOptions;
  43. private $entityPermission;
  44. private $contentWidth;
  45. private $sidebarWidth;
  46. public function __construct()
  47. {
  48. $this->customPageTitles = [Crud::PAGE_DETAIL => null, Crud::PAGE_EDIT => null, Crud::PAGE_INDEX => null, Crud::PAGE_NEW => null];
  49. $this->helpMessages = [Crud::PAGE_DETAIL => null, Crud::PAGE_EDIT => null, Crud::PAGE_INDEX => null, Crud::PAGE_NEW => null];
  50. $this->datePattern = 'medium';
  51. $this->timePattern = 'medium';
  52. $this->dateTimePattern = ['medium', 'medium'];
  53. $this->dateIntervalFormat = '%%y Year(s) %%m Month(s) %%d Day(s)';
  54. $this->defaultSort = [];
  55. $this->searchFields = [];
  56. $this->showEntityActionsAsDropdown = true;
  57. $this->formThemes = ['@EasyAdmin/crud/form_theme.html.twig'];
  58. $this->newFormOptions = KeyValueStore::new();
  59. $this->editFormOptions = KeyValueStore::new();
  60. $this->overriddenTemplates = [];
  61. }
  62. public function getControllerFqcn(): ?string
  63. {
  64. return $this->controllerFqcn;
  65. }
  66. public function setControllerFqcn(string $fqcn): void
  67. {
  68. $this->controllerFqcn = $fqcn;
  69. }
  70. public function getCurrentPage(): ?string
  71. {
  72. return $this->pageName;
  73. }
  74. public function setPageName(?string $pageName): void
  75. {
  76. $this->pageName = $pageName;
  77. }
  78. public function getEntityFqcn(): string
  79. {
  80. return $this->entityFqcn;
  81. }
  82. public function setEntityFqcn(string $entityFqcn): void
  83. {
  84. $this->entityFqcn = $entityFqcn;
  85. }
  86. public function getEntityLabelInSingular($entityInstance = null, $pageName = null): ?string
  87. {
  88. if (null === $this->entityLabelInSingular) {
  89. return null;
  90. }
  91. if (\is_string($this->entityLabelInSingular)) {
  92. return $this->entityLabelInSingular;
  93. }
  94. return ($this->entityLabelInSingular)($entityInstance, $pageName);
  95. }
  96. /**
  97. * @param string|callable $label
  98. */
  99. public function setEntityLabelInSingular($label): void
  100. {
  101. $this->entityLabelInSingular = $label;
  102. }
  103. public function getEntityLabelInPlural($entityInstance = null, $pageName = null): ?string
  104. {
  105. if (null === $this->entityLabelInPlural) {
  106. return null;
  107. }
  108. if (\is_string($this->entityLabelInPlural)) {
  109. return $this->entityLabelInPlural;
  110. }
  111. return ($this->entityLabelInPlural)($entityInstance, $pageName);
  112. }
  113. /**
  114. * @param string|callable $label
  115. */
  116. public function setEntityLabelInPlural($label): void
  117. {
  118. $this->entityLabelInPlural = $label;
  119. }
  120. public function getCustomPageTitle(string $pageName = null, $entityInstance = null): ?string
  121. {
  122. $title = $this->customPageTitles[$pageName ?? $this->pageName];
  123. if (\is_callable($title)) {
  124. return null !== $entityInstance ? $title($entityInstance) : $title();
  125. }
  126. return $title;
  127. }
  128. /**
  129. * @param string|callable $pageTitle
  130. */
  131. public function setCustomPageTitle(string $pageName, $pageTitle): void
  132. {
  133. $this->customPageTitles[$pageName] = $pageTitle;
  134. }
  135. public function getDefaultPageTitle(string $pageName = null, $entityInstance = null): ?string
  136. {
  137. if (null !== $entityInstance) {
  138. if (method_exists($entityInstance, '__toString')) {
  139. $entityAsString = (string) $entityInstance;
  140. if (!empty($entityAsString)) {
  141. return $entityAsString;
  142. }
  143. }
  144. }
  145. return $this->defaultPageTitles[$pageName ?? $this->pageName] ?? null;
  146. }
  147. public function getHelpMessage(string $pageName = null): string
  148. {
  149. return $this->helpMessages[$pageName ?? $this->pageName] ?? '';
  150. }
  151. public function getHelpMessages(): array
  152. {
  153. return $this->helpMessages;
  154. }
  155. public function setHelpMessage(string $pageName, string $helpMessage): void
  156. {
  157. $this->helpMessages[$pageName] = $helpMessage;
  158. }
  159. public function getDatePattern(): ?string
  160. {
  161. return $this->datePattern;
  162. }
  163. public function setDatePattern(?string $format): void
  164. {
  165. $this->datePattern = $format;
  166. }
  167. public function getTimePattern(): ?string
  168. {
  169. return $this->timePattern;
  170. }
  171. public function setTimePattern(?string $format): void
  172. {
  173. $this->timePattern = $format;
  174. }
  175. public function getDateTimePattern(): array
  176. {
  177. return $this->dateTimePattern;
  178. }
  179. public function setDateTimePattern(string $dateFormatOrPattern, string $timeFormat = DateTimeField::FORMAT_NONE): void
  180. {
  181. $this->dateTimePattern = [$dateFormatOrPattern, $timeFormat];
  182. }
  183. public function getDateIntervalFormat(): string
  184. {
  185. return $this->dateIntervalFormat;
  186. }
  187. public function setDateIntervalFormat(string $format): void
  188. {
  189. $this->dateIntervalFormat = $format;
  190. }
  191. public function getTimezone(): ?string
  192. {
  193. return $this->timezone;
  194. }
  195. public function setTimezone(string $timezoneId): void
  196. {
  197. $this->timezone = $timezoneId;
  198. }
  199. public function getNumberFormat(): ?string
  200. {
  201. return $this->numberFormat;
  202. }
  203. public function setNumberFormat(string $numberFormat): void
  204. {
  205. $this->numberFormat = $numberFormat;
  206. }
  207. public function getDefaultSort(): array
  208. {
  209. return $this->defaultSort;
  210. }
  211. public function setDefaultSort(array $defaultSort): void
  212. {
  213. $this->defaultSort = $defaultSort;
  214. }
  215. public function getSearchFields(): ?array
  216. {
  217. return $this->searchFields;
  218. }
  219. public function setSearchFields(?array $searchFields): void
  220. {
  221. $this->searchFields = $searchFields;
  222. }
  223. public function isSearchEnabled(): bool
  224. {
  225. return null !== $this->searchFields;
  226. }
  227. public function showEntityActionsAsDropdown(): bool
  228. {
  229. return $this->showEntityActionsAsDropdown;
  230. }
  231. public function setShowEntityActionsAsDropdown(bool $showAsDropdown): void
  232. {
  233. $this->showEntityActionsAsDropdown = $showAsDropdown;
  234. }
  235. public function getPaginator(): PaginatorDto
  236. {
  237. return $this->paginatorDto;
  238. }
  239. public function setPaginator(PaginatorDto $paginatorDto): void
  240. {
  241. $this->paginatorDto = $paginatorDto;
  242. }
  243. public function getOverriddenTemplates(): array
  244. {
  245. return $this->overriddenTemplates;
  246. }
  247. public function overrideTemplate(string $templateName, string $templatePath): void
  248. {
  249. $this->overriddenTemplates[$templateName] = $templatePath;
  250. }
  251. public function getFormThemes(): array
  252. {
  253. return $this->formThemes;
  254. }
  255. public function setFormThemes(array $formThemes): void
  256. {
  257. $this->formThemes = $formThemes;
  258. }
  259. public function getNewFormOptions(): ?KeyValueStore
  260. {
  261. return $this->newFormOptions;
  262. }
  263. public function getEditFormOptions(): ?KeyValueStore
  264. {
  265. return $this->editFormOptions;
  266. }
  267. public function setNewFormOptions(KeyValueStore $formOptions): void
  268. {
  269. $this->newFormOptions = $formOptions;
  270. }
  271. public function setEditFormOptions(KeyValueStore $formOptions): void
  272. {
  273. $this->editFormOptions = $formOptions;
  274. }
  275. public function getEntityPermission(): ?string
  276. {
  277. return $this->entityPermission;
  278. }
  279. public function setEntityPermission(string $entityPermission): void
  280. {
  281. $this->entityPermission = $entityPermission;
  282. }
  283. public function getCurrentAction(): string
  284. {
  285. return $this->actionName;
  286. }
  287. public function setCurrentAction(string $actionName): void
  288. {
  289. $this->actionName = $actionName;
  290. }
  291. public function getActionsConfig(): ActionConfigDto
  292. {
  293. return $this->actionConfigDto;
  294. }
  295. public function setActionsConfig(ActionConfigDto $actionConfig): void
  296. {
  297. $this->actionConfigDto = $actionConfig;
  298. }
  299. public function getFiltersConfig(): FilterConfigDto
  300. {
  301. return $this->filters;
  302. }
  303. public function setFiltersConfig(FilterConfigDto $filterConfig): void
  304. {
  305. $this->filters = $filterConfig;
  306. }
  307. public function getContentWidth(): ?string
  308. {
  309. return $this->contentWidth;
  310. }
  311. public function setContentWidth(string $contentWidth): void
  312. {
  313. $this->contentWidth = $contentWidth;
  314. }
  315. public function getSidebarWidth(): ?string
  316. {
  317. return $this->sidebarWidth;
  318. }
  319. public function setSidebarWidth(string $sidebarWidth): void
  320. {
  321. $this->sidebarWidth = $sidebarWidth;
  322. }
  323. }