Browse Source

Correction et ajout de methode custom dans définition

feature/symfony6.1
Fabien Normand 1 month ago
parent
commit
21c63426e9
3 changed files with 74 additions and 64 deletions
  1. +69
    -63
      Definition/Field/AbstractFieldDefinition.php
  2. +4
    -0
      Resources/assets/app/adminlte/form/form.scss
  3. +1
    -1
      Solver/Ticket/TicketSolver.php

+ 69
- 63
Definition/Field/AbstractFieldDefinition.php View File

use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\File\Exception\FileException;


abstract class AbstractFieldDefinition abstract class AbstractFieldDefinition
{ {
} }


abstract public function configureFields(): array; abstract public function configureFields(): array;
public function configureCustom(string $pageName): array
{
return array();
}


public function configureFieldsBase(): array public function configureFieldsBase(): array
{ {
return [ return [
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'title' => TextField::new('title'),
'description' => CKEditorField::new('description'),
'image' => ImageManagerField::new('image'),
'metaTitle' => TextField::new('metaTitle')
->setLabel('Meta : title')
->setHelp('Affiché dans les résultats de recherche Google'),
'metaDescription' => TextareaField::new('metaDescription')
->setLabel('Meta : description')
->setHelp('Affiché dans les résultats de recherche Google'),
'oldUrls' => CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)
->setLabel('Anciennes urls du document')
->hideOnIndex(),
'openGraphTitle' => TextField::new('openGraphTitle')
->setLabel('OpenGraph : titre')
->setHelp('Utilisé par les réseaux sociaux pour récupérer le titre de la page'),
'openGraphDescription' => TextareaField::new('openGraphDescription')
->setLabel('OpenGraph : description')
->setHelp('Utilisé par les réseaux sociaux pour récupérer la description de la page'),
'openGraphImage' => ImageManagerField::new('openGraphImage')
->setLabel('OpenGraph : image'),
'devAlias' => TextField::new('devAlias')->hideOnIndex(),
'status' => StatusField::new('status')->setSortable(true),
'createdAt' => DateTimeField::new('createdAt')->setSortable(true),
'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true),
'createdBy' => \EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField::new('createdBy'),
'updatedBy' => AssociationField::new('updatedBy')
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'title' => TextField::new('title'),
'description' => CKEditorField::new('description'),
'image' => ImageManagerField::new('image'),
'metaTitle' => TextField::new('metaTitle')
->setLabel('Meta : title')
->setHelp('Affiché dans les résultats de recherche Google'),
'metaDescription' => TextareaField::new('metaDescription')
->setLabel('Meta : description')
->setHelp('Affiché dans les résultats de recherche Google'),
'oldUrls' => CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)
->setLabel('Anciennes urls du document')
->hideOnIndex(),
'openGraphTitle' => TextField::new('openGraphTitle')
->setLabel('OpenGraph : titre')
->setHelp('Utilisé par les réseaux sociaux pour récupérer le titre de la page'),
'openGraphDescription' => TextareaField::new('openGraphDescription')
->setLabel('OpenGraph : description')
->setHelp('Utilisé par les réseaux sociaux pour récupérer la description de la page'),
'openGraphImage' => ImageManagerField::new('openGraphImage')
->setLabel('OpenGraph : image'),
'devAlias' => TextField::new('devAlias')->hideOnIndex(),
'status' => StatusField::new('status')->setSortable(true),
'createdAt' => DateTimeField::new('createdAt')->setSortable(true),
'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true),
'createdBy' => \EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField::new('createdBy'),
'updatedBy' => AssociationField::new('updatedBy')
]; ];
} }


public function configurePanelSeo(): array public function configurePanelSeo(): array
{ {
return [ return [
'metaTitle',
'metaDescription',
'oldUrls'
'metaTitle',
'metaDescription',
'oldUrls'
]; ];
} }


public function configurePanelOpengraph(): array public function configurePanelOpengraph(): array
{ {
return [ return [
'openGraphTitle',
'openGraphDescription',
'openGraphImage'
'openGraphTitle',
'openGraphDescription',
'openGraphImage'
]; ];
} }


public function configurePanelConf(): array public function configurePanelConf(): array
{ {
return [ return [
'devAlias',
'devAlias',
]; ];
} }


public function getFields(string $pageName = ''): array public function getFields(string $pageName = ''): array
{ {
if($pageName == Crud::PAGE_INDEX) {
if ($pageName == Crud::PAGE_INDEX) {
return $this->buildFieldArray($this->configureIndex()); return $this->buildFieldArray($this->configureIndex());
}
elseif($pageName == Crud::PAGE_DETAIL) {
} elseif ($pageName == Crud::PAGE_DETAIL) {
return $this->buildFieldArray($this->configureDetail()); return $this->buildFieldArray($this->configureDetail());
}
elseif($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW) {
} elseif ($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW) {
return $this->buildFieldArrayForm(); return $this->buildFieldArrayForm();
} else {
try {
return $this->buildFieldArray($this->configureCustom($pageName));
} catch (FileException $e) {
throw new \ErrorException("Une erreur est survenue lors de l'upload du fichier.");
}
} }


return []; return [];
public function getAllFields(): array public function getAllFields(): array
{ {
return array_merge( return array_merge(
$this->configureFieldsBase(),
$this->configureFields(),
$this->configureFieldsBase(),
$this->configureFields(),
); );
} }


$allFieldArray = $this->getAllFields(); $allFieldArray = $this->getAllFields();


$fieldArray = []; $fieldArray = [];
foreach($configureFieldArray as $fieldName) {
if(isset($allFieldArray[$fieldName])) {
foreach ($configureFieldArray as $fieldName) {
if (isset($allFieldArray[$fieldName])) {
$fieldArray[$fieldName] = $allFieldArray[$fieldName]; $fieldArray[$fieldName] = $allFieldArray[$fieldName];
}
else {
throw new \ErrorException('Le field "'.$fieldName.'" n\'est pas défini dans configureFields()');
} else {
throw new \ErrorException('Le field "' . $fieldName . '" n\'est pas défini dans configureFields()');
} }
} }


$fieldArray = []; $fieldArray = [];
$panelArray = $this->configurePanels(); $panelArray = $this->configurePanels();


if($panelArray && count($panelArray) > 0) {
foreach($panelArray as $panel) {
if ($panelArray && count($panelArray) > 0) {
foreach ($panelArray as $panel) {
$fieldArray = array_merge( $fieldArray = array_merge(
$fieldArray,
$this->buildFieldArrayFormByPanel($panel)
$fieldArray,
$this->buildFieldArrayFormByPanel($panel)
); );
} }
}
else {
} else {
$fieldArray = $this->buildFieldArray($this->configureForm()); $fieldArray = $this->buildFieldArray($this->configureForm());
} }


protected function buildFieldArrayFormByPanel(string $panel): array protected function buildFieldArrayFormByPanel(string $panel): array
{ {
$method = 'configurePanel' . ucfirst($panel); $method = 'configurePanel' . ucfirst($panel);
if(method_exists($this, $method)) {
if (method_exists($this, $method)) {
$panelFieldArray = $this->$method(); $panelFieldArray = $this->$method();
}
else{
} else {
throw new \Exception($method . ' n\'existe pas '); throw new \Exception($method . ' n\'existe pas ');
} }


$fieldPanel = FormField::addPanel($panel); $fieldPanel = FormField::addPanel($panel);
$method = 'panel'.ucfirst($panel).'CustomOptions';
if(method_exists($this, $method)) {
foreach ($this->$method() as $customOptionKey => $customOptionValue){
$method = 'panel' . ucfirst($panel) . 'CustomOptions';
if (method_exists($this, $method)) {
foreach ($this->$method() as $customOptionKey => $customOptionValue) {
$fieldPanel->setCustomOption($customOptionKey, $customOptionValue); $fieldPanel->setCustomOption($customOptionKey, $customOptionValue);
} }


} }


return array_merge( return array_merge(
[
'panel_' . $panel => $fieldPanel
[
'panel_' . $panel => $fieldPanel


],
$this->buildFieldArray($panelFieldArray)
],
$this->buildFieldArray($panelFieldArray)
); );
} }



+ 4
- 0
Resources/assets/app/adminlte/form/form.scss View File

display: none; display: none;
} }


.form-inline{
label{margin-right: 10px;}
.form-control{margin-right: 10px;}
}

+ 1
- 1
Solver/Ticket/TicketSolver.php View File



class TicketSolver class TicketSolver
{ {
public function getTypeChoices($context = 'backend'): array
public static function getTypeChoices($context = 'backend'): array
{ {
return [ return [
TicketModel::TYPE_GENERAL_QUESTION, TicketModel::TYPE_GENERAL_QUESTION,

Loading…
Cancel
Save