Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

97 Zeilen
3.0KB

  1. <?php
  2. namespace Lc\SovBundle\Definition\Field;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  6. use Lc\SovBundle\Field\CollectionField;
  7. use Lc\SovBundle\Translation\TranslatorAdmin;
  8. use PhpParser\Node\Expr\Throw_;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. abstract class AbstractFieldDefinition
  11. {
  12. protected array $panels;
  13. protected array $fieldsByPanel;
  14. protected array $fieldList;
  15. protected bool $isPopulate = false;
  16. protected TranslatorAdmin $translatorAdmin;
  17. abstract public function configurePanels(): array;
  18. abstract public function configureFields(): array;
  19. public function __construct(TranslatorAdmin $translatorAdmin)
  20. {
  21. $this->translatorAdmin = $translatorAdmin;
  22. }
  23. protected function populate(): void
  24. {
  25. if ($this->isPopulate === false) {
  26. $this->fieldList = $this->configureFields();
  27. $this->panels = $this->configurePanels();
  28. foreach ($this->panels as $panel) {
  29. $method = 'configureFieldsPanel' . ucfirst($panel);
  30. if (method_exists($this, $method)) {
  31. $this->fieldsByPanel[$panel] = array_merge(
  32. array('panel_' . $panel => FormField::addPanel($panel)),
  33. $this->$method()
  34. );
  35. $this->fieldList = array_merge($this->fieldList, $this->fieldsByPanel[$panel]);
  36. }else{
  37. throw new \Exception($method . ' n\'esxite pas ');
  38. }
  39. }
  40. $this->isPopulate = false;
  41. }
  42. }
  43. public function getFieldList()
  44. {
  45. $this->populate();
  46. return $this->fieldList;
  47. }
  48. public function getFieldListByPanel($panel)
  49. {
  50. $this->populate();
  51. return $this->fieldsByPanel[$panel];
  52. }
  53. public function getPanelList()
  54. {
  55. $this->populate();
  56. return $this->fieldsByPanel;
  57. }
  58. public function configureFieldsPanelSeo(): array
  59. {
  60. return array(
  61. 'metaTitle' => TextField::new('metaTitle')
  62. ->setLabel('Meta Title')
  63. ->setHelp('Affiché dans les résultats de recherche Google')
  64. ->hideOnIndex(),
  65. 'metaDescription' => TextareaField::new('metaDescription')
  66. ->setLabel('Meta description')
  67. ->setHelp('Affiché dans les résultats de recherche Google')
  68. ->hideOnIndex(),
  69. 'oldUrls' => CollectionField::new('oldUrls')
  70. ->setFormTypeOption('entry_type', TextType::class)
  71. ->setLabel('Anciennes urls du document')
  72. ->hideOnIndex(),
  73. );
  74. }
  75. public function configureFieldsPanelConf(): array
  76. {
  77. return [
  78. //FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
  79. 'devAlias' => TextField::new('devAlias')->hideOnIndex(),
  80. ];
  81. }
  82. }