Quellcode durchsuchen

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

develop
Fabien Normand vor 3 Jahren
Ursprung
Commit
b2a16a8be7
3 geänderte Dateien mit 154 neuen und 81 gelöschten Zeilen
  1. +21
    -0
      Component/NumberComponent.php
  2. +124
    -74
      Definition/Field/AbstractFieldDefinition.php
  3. +9
    -7
      Resources/translations/admin.fr.yaml

+ 21
- 0
Component/NumberComponent.php Datei anzeigen

@@ -10,5 +10,26 @@ class NumberComponent
return round((($price * 100)) / 100, $precision);
}

public function numberToWord(int $number): string
{
$numberWordArray = [
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten'
];

if(isset($numberWordArray[$number])) {
return $numberWordArray[$number];
}

return '';
}
}

+ 124
- 74
Definition/Field/AbstractFieldDefinition.php Datei anzeigen

@@ -4,117 +4,167 @@ namespace Lc\SovBundle\Definition\Field;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Translation\TranslatorAdmin;
use PhpParser\Node\Expr\Throw_;
use Symfony\Component\Form\Extension\Core\Type\TextType;

abstract class AbstractFieldDefinition
{
protected array $panels;
protected array $fieldsByPanel;
protected array $fieldList;
protected bool $isPopulate = false;
protected TranslatorAdmin $translatorAdmin;

abstract public function configureFieldsIndex(): array;
abstract public function configurePanels(): array;
abstract public function configureFields(): array;

public function __construct(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) {
$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)
);
}

}

+ 9
- 7
Resources/translations/admin.fr.yaml Datei anzeigen

@@ -41,13 +41,6 @@ action:
save_and_continue: Sauvegarder et continuer l'édition
save_and_add_another: Créer et ajouter un nouvel élément

flash_message:
create: Le contenu "%name%" a été créé avec succès.
update: Le contenu "%name%" a été mis à jour avec succès.
delete: Le contenu "%name%" a été supprimé avec succès.
sort: Position modifiée
duplicate: Le document a bien été dupliqué

entity:
User:
label: Utilisateur
@@ -140,6 +133,15 @@ entity:
configuration: Configuration
gallery: Galerie
seo: Référencement
flashes:
success:
created: L'élément a bien été créé
updated: L'élément a bien été mis à jour
deleted: L'élément a bien été supprimé
error:
created: Une erreur est survenue à la création de l'élément
updated: Une erreur est survenue à la mis à jour de l'élément
deleted: Une erreur est survenue à la suppression de l'élément
form:
account_profile:
message:

Laden…
Abbrechen
Speichern