|
|
|
|
|
|
|
|
|
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; |
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
use Lc\SovBundle\Field\CollectionField; |
|
|
use Lc\SovBundle\Field\CollectionField; |
|
|
|
|
|
use Lc\SovBundle\Field\StatusField; |
|
|
use Lc\SovBundle\Translation\TranslatorAdmin; |
|
|
use Lc\SovBundle\Translation\TranslatorAdmin; |
|
|
use PhpParser\Node\Expr\Throw_; |
|
|
use PhpParser\Node\Expr\Throw_; |
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
|
|
|
|
|
|
|
abstract class AbstractFieldDefinition |
|
|
abstract class AbstractFieldDefinition |
|
|
{ |
|
|
{ |
|
|
protected array $panels; |
|
|
|
|
|
protected array $fieldsByPanel; |
|
|
|
|
|
protected array $fieldList; |
|
|
|
|
|
protected bool $isPopulate = false; |
|
|
|
|
|
protected TranslatorAdmin $translatorAdmin; |
|
|
protected TranslatorAdmin $translatorAdmin; |
|
|
|
|
|
|
|
|
abstract public function configureFieldsIndex(): array; |
|
|
|
|
|
abstract public function configurePanels(): array; |
|
|
|
|
|
abstract public function configureFields(): array; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(TranslatorAdmin $translatorAdmin) |
|
|
public function __construct(TranslatorAdmin $translatorAdmin) |
|
|
{ |
|
|
{ |
|
|
$this->translatorAdmin = $translatorAdmin; |
|
|
$this->translatorAdmin = $translatorAdmin; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected function populate(): void |
|
|
|
|
|
|
|
|
abstract public function configureFields(): array; |
|
|
|
|
|
|
|
|
|
|
|
public function configureFieldsBase(): array |
|
|
{ |
|
|
{ |
|
|
if ($this->isPopulate === false) { |
|
|
|
|
|
$this->fieldList = [] ; |
|
|
|
|
|
$allFieldArray = $this->configureFields();; |
|
|
|
|
|
$this->panels = $this->configurePanels(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->panels as $panel) { |
|
|
|
|
|
|
|
|
|
|
|
$method = 'configureFieldsPanel' . ucfirst($panel); |
|
|
|
|
|
if (method_exists($this, $method)) { |
|
|
|
|
|
|
|
|
|
|
|
$fieldArray = $this->$method(); |
|
|
|
|
|
foreach($fieldArray as $key => $field) { |
|
|
|
|
|
if(is_string($field)) { |
|
|
|
|
|
unset($fieldArray[$key]); |
|
|
|
|
|
$fieldArray[$field] = $allFieldArray[$field]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->fieldsByPanel[$panel] = array_merge( |
|
|
|
|
|
['panel_' . $panel => FormField::addPanel($panel)], |
|
|
|
|
|
$fieldArray |
|
|
|
|
|
); |
|
|
|
|
|
$this->fieldList = array_merge($this->fieldList, $this->fieldsByPanel[$panel]); |
|
|
|
|
|
}else{ |
|
|
|
|
|
throw new \Exception($method . ' n\'existe pas '); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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), |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$this->fieldList = array_merge($this->fieldList, $allFieldArray); |
|
|
|
|
|
|
|
|
public function configureDefaultFields(): array |
|
|
|
|
|
{ |
|
|
|
|
|
return array_keys($this->configureFields()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$this->isPopulate = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 getFieldList(string $pageName = '') |
|
|
|
|
|
|
|
|
public function configurePanelSeo(): array |
|
|
{ |
|
|
{ |
|
|
$this->populate(); |
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
'metaTitle', |
|
|
|
|
|
'metaDescription', |
|
|
|
|
|
'oldUrls' |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function configurePanelConf(): array |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
'devAlias', |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getFields(string $pageName = ''): array |
|
|
|
|
|
{ |
|
|
if($pageName == Crud::PAGE_INDEX) { |
|
|
if($pageName == Crud::PAGE_INDEX) { |
|
|
$fieldArray = []; |
|
|
|
|
|
foreach($this->configureFieldsIndex() as $fieldName) { |
|
|
|
|
|
$fieldArray[] = $this->fieldList[$fieldName]; |
|
|
|
|
|
} |
|
|
|
|
|
return $fieldArray; |
|
|
|
|
|
|
|
|
return $this->buildFieldArray($this->configureIndex()); |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
return $this->fieldList; |
|
|
|
|
|
|
|
|
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 getFieldListByPanel($panel) |
|
|
|
|
|
|
|
|
public function getAllFields(): array |
|
|
{ |
|
|
{ |
|
|
$this->populate(); |
|
|
|
|
|
return $this->fieldsByPanel[$panel]; |
|
|
|
|
|
|
|
|
return array_merge( |
|
|
|
|
|
$this->configureFieldsBase(), |
|
|
|
|
|
$this->configureFields() |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPanelList() |
|
|
|
|
|
|
|
|
public function getFieldsByPanel(string $panel): array |
|
|
{ |
|
|
{ |
|
|
$this->populate(); |
|
|
|
|
|
return $this->fieldsByPanel; |
|
|
|
|
|
|
|
|
return $this->buildFieldArrayFormByPanel($panel); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function configureFieldsPanelSeo(): array |
|
|
|
|
|
|
|
|
protected function buildFieldArray(array $configureFieldArray): array |
|
|
{ |
|
|
{ |
|
|
return array( |
|
|
|
|
|
'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(), |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
$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; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function configureFieldsPanelConf(): array |
|
|
|
|
|
|
|
|
protected function buildFieldArrayForm(): array |
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
|
|
|
//FormField::addPanel('configuration')->setTemplateName('crud/field/generic'), |
|
|
|
|
|
'devAlias' => TextField::new('devAlias')->hideOnIndex(), |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
$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) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |