translatorAdmin = $translatorAdmin; } abstract public function configureFields(): array; public function configureFieldsBase(): array { return [ 'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true), 'metaTitle' => TextField::new('metaTitle') ->setLabel('Meta Title') ->setHelp('Affiché dans les résultats de recherche Google') ->hideOnIndex(), 'metaDescription' => TextareaField::new('metaDescription') ->setLabel('Meta description') ->setHelp('Affiché dans les résultats de recherche Google') ->hideOnIndex(), 'oldUrls' => CollectionField::new('oldUrls') ->setFormTypeOption('entry_type', TextType::class) ->setLabel('Anciennes urls du document') ->hideOnIndex(), 'devAlias' => TextField::new('devAlias')->hideOnIndex(), 'status' => StatusField::new('status')->setSortable(true), ]; } public function configureDefaultFields(): array { return array_keys($this->configureFields()); } public function configureIndex(): array { return $this->configureDefaultFields(); } public function configureDetail(): array { return $this->configureDefaultFields(); } public function configureForm(): array { return $this->configureDefaultFields(); } public function configurePanels(): array { return []; } public function configurePanelSeo(): array { return [ 'metaTitle', 'metaDescription', 'oldUrls' ]; } public function configurePanelConf(): array { return [ 'devAlias', ]; } public function getFields(string $pageName = ''): array { if($pageName == Crud::PAGE_INDEX) { return $this->buildFieldArray($this->configureIndex()); } elseif($pageName == Crud::PAGE_DETAIL) { return $this->buildFieldArray($this->configureDetail()); } elseif($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW) { return $this->buildFieldArrayForm(); } return []; } public function getAllFields(): array { return array_merge( $this->configureFieldsBase(), $this->configureFields() ); } public function getFieldsByPanel(string $panel): array { return $this->buildFieldArrayFormByPanel($panel); } protected function buildFieldArray(array $configureFieldArray): array { $allFieldArray = $this->getAllFields(); $fieldArray = []; foreach($configureFieldArray as $fieldName) { if(isset($allFieldArray[$fieldName])) { $fieldArray[] = $allFieldArray[$fieldName]; } else { throw new \ErrorException('Le field "'.$fieldName.'" n\'est pas défini dans configureFields()'); } } return $fieldArray; } protected function buildFieldArrayForm(): array { $fieldArray = []; $panelArray = $this->configurePanels(); if($panelArray && count($panelArray) > 0) { foreach($panelArray as $panel) { $fieldArray = array_merge( $fieldArray, $this->buildFieldArrayFormByPanel($panel) ); } } else { $fieldArray = $this->buildFieldArray($this->configureForm()); } return $fieldArray; } protected function buildFieldArrayFormByPanel(string $panel): array { $method = 'configurePanel' . ucfirst($panel); if(method_exists($this, $method)) { $panelFieldArray = $this->$method(); } else{ throw new \Exception($method . ' n\'existe pas '); } return array_merge( ['panel_' . $panel => FormField::addPanel($panel)], $this->buildFieldArray($panelFieldArray) ); } }