Browse Source

AbstractFieldDefinition

develop
Guillaume 3 years ago
parent
commit
e30c40a6e1
1 changed files with 18 additions and 4 deletions
  1. +18
    -4
      Definition/Field/AbstractFieldDefinition.php

+ 18
- 4
Definition/Field/AbstractFieldDefinition.php View File



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;
public function configureFieldsBase(): array public function configureFieldsBase(): array
{ {
return [ return [
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'metaTitle' => TextField::new('metaTitle') 'metaTitle' => TextField::new('metaTitle')
->setLabel('Meta Title') ->setLabel('Meta Title')
->setHelp('Affiché dans les résultats de recherche Google') ->setHelp('Affiché dans les résultats de recherche Google')
->setLabel('Anciennes urls du document') ->setLabel('Anciennes urls du document')
->hideOnIndex(), ->hideOnIndex(),
'devAlias' => TextField::new('devAlias')->hideOnIndex(), 'devAlias' => TextField::new('devAlias')->hideOnIndex(),
'status' => StatusField::new('status')->setSortable(true),
]; ];
} }


); );
} }


public function buildFieldArray(array $configureFieldArray): array
public function getFieldsByPanel(string $panel): array
{
return $this->buildFieldArrayFormByPanel($panel);
}

protected function buildFieldArray(array $configureFieldArray): array
{ {
$allFieldArray = $this->getAllFields(); $allFieldArray = $this->getAllFields();


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


return $fieldArray; return $fieldArray;
} }


public function buildFieldArrayForm(): array
protected function buildFieldArrayForm(): array
{ {
$fieldArray = []; $fieldArray = [];
$panelArray = $this->configurePanels(); $panelArray = $this->configurePanels();
return $fieldArray; return $fieldArray;
} }


public 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)) {

Loading…
Cancel
Save