Bläddra i källkod

Correction et ajout de methode custom dans définition

feature/symfony6.1
Fabien Normand 1 månad sedan
förälder
incheckning
21c63426e9
3 ändrade filer med 74 tillägg och 64 borttagningar
  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 Visa fil

@@ -15,6 +15,7 @@ use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\File\Exception\FileException;

abstract class AbstractFieldDefinition
{
@@ -26,38 +27,42 @@ abstract class AbstractFieldDefinition
}

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

public function configureFieldsBase(): array
{
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')
];
}

@@ -89,38 +94,42 @@ abstract class AbstractFieldDefinition
public function configurePanelSeo(): array
{
return [
'metaTitle',
'metaDescription',
'oldUrls'
'metaTitle',
'metaDescription',
'oldUrls'
];
}

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

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

public function getFields(string $pageName = ''): array
{
if($pageName == Crud::PAGE_INDEX) {
if ($pageName == Crud::PAGE_INDEX) {
return $this->buildFieldArray($this->configureIndex());
}
elseif($pageName == Crud::PAGE_DETAIL) {
} elseif ($pageName == Crud::PAGE_DETAIL) {
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();
} 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 [];
@@ -129,8 +138,8 @@ abstract class AbstractFieldDefinition
public function getAllFields(): array
{
return array_merge(
$this->configureFieldsBase(),
$this->configureFields(),
$this->configureFieldsBase(),
$this->configureFields(),
);
}

@@ -144,12 +153,11 @@ abstract class AbstractFieldDefinition
$allFieldArray = $this->getAllFields();

$fieldArray = [];
foreach($configureFieldArray as $fieldName) {
if(isset($allFieldArray[$fieldName])) {
foreach ($configureFieldArray as $fieldName) {
if (isset($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()');
}
}

@@ -161,15 +169,14 @@ abstract class AbstractFieldDefinition
$fieldArray = [];
$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,
$this->buildFieldArrayFormByPanel($panel)
$fieldArray,
$this->buildFieldArrayFormByPanel($panel)
);
}
}
else {
} else {
$fieldArray = $this->buildFieldArray($this->configureForm());
}

@@ -179,28 +186,27 @@ abstract class AbstractFieldDefinition
protected function buildFieldArrayFormByPanel(string $panel): array
{
$method = 'configurePanel' . ucfirst($panel);
if(method_exists($this, $method)) {
if (method_exists($this, $method)) {
$panelFieldArray = $this->$method();
}
else{
} else {
throw new \Exception($method . ' n\'existe pas ');
}

$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);
}

}

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

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


+ 4
- 0
Resources/assets/app/adminlte/form/form.scss Visa fil

@@ -52,3 +52,7 @@ legend {
display: none;
}

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

+ 1
- 1
Solver/Ticket/TicketSolver.php Visa fil

@@ -7,7 +7,7 @@ use Lc\SovBundle\Model\Ticket\TicketModel;

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

Laddar…
Avbryt
Spara