Parcourir la source

Address dans Merchant

feature/ticket
Fab il y a 3 ans
Parent
révision
ae2ca516df
4 fichiers modifiés avec 151 ajouts et 0 suppressions
  1. +5
    -0
      Controller/Merchant/MerchantAdminController.php
  2. +26
    -0
      Field/Address/AddressField.php
  3. +103
    -0
      Form/Address/AddressType.php
  4. +17
    -0
      Resources/translations/admin.fr.yaml

+ 5
- 0
Controller/Merchant/MerchantAdminController.php Voir le fichier

@@ -7,6 +7,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
@@ -32,6 +33,10 @@ abstract class MerchantAdminController extends AbstractAdminController
->setRequired(true)
->hideOnIndex(),
StatusField::new('status'),

FormField::addPanel('address'),
AddressField::new('address')

],
$panel
);

+ 26
- 0
Field/Address/AddressField.php Voir le fichier

@@ -0,0 +1,26 @@
<?php

namespace Lc\CaracoleBundle\Field\Address;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Lc\CaracoleBundle\Form\Address\AddressType;

/**
* @author La clic ! <contact@laclic.fr>
*/
final class AddressField implements FieldInterface
{
use FieldTrait;

public static function new(string $propertyName, ?string $label = null): self
{
return (new self())
->hideOnIndex()
->setProperty($propertyName)
->setLabel($label)
//->setTemplatePath('@LcSov/adminlte/crud/field/toggle.html.twig')
->setFormType(AddressType::class);
}

}

+ 103
- 0
Form/Address/AddressType.php Voir le fichier

@@ -0,0 +1,103 @@
<?php

namespace Lc\CaracoleBundle\Form\Address;

use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Address\AddressModel;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AddressType extends AbstractType
{
protected $em;
protected $translatorAdmin;

public function __construct(EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin)
{
$this->em = $entityManager;
$this->translatorAdmin = $translatorAdmin;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class, ['label' => 'Titre'])
->add(
'type',
ChoiceType::class,
[
'label' => 'Type',
'choices' => [
$this->translatorAdmin->transField(
'typeOptions.'.AddressModel::TYPE_INDIVIDUAL,
'Address'
) => AddressModel::TYPE_INDIVIDUAL,
$this->translatorAdmin->transField(
'typeOptions.'.AddressModel::TYPE_LEGAL_PERSON,
'Address'
) => AddressModel::TYPE_LEGAL_PERSON,
],
]
)
->add(
'civility',
ChoiceType::class,
[
'label' => 'Civilité',
'required' => false,
'choices' => [
'--' => '',
'Femme' => 1,
'Homme' => 0,
],
]
)
->add('lastname', TextType::class, ['required' => false])
->add('firstname', TextType::class, ['required' => false])
->add('zip', TextType::class)
->add('city', TextType::class)
->add('address', TextType::class)
->add(
'phone',
CollectionType::class,
[
'allow_add' => true,
'allow_delete' => true,
'entry_options' => [
'label' => false,
],
'required' => false,
'row_attr' => array(
'data-reindex-key' => true,
'class' => 'field-collection',

),
'attr' => array(
'class' => 'field-collection-group',
),
]
)
->add('company', TextType::class, ['required' => false])
->add('siret', TextType::class, ['required' => false])
->add('tva', TextType::class, ['required' => false])
->add('country', HiddenType::class, ['data' => 'France'])
->add('status', HiddenType::class, ['data' => '1']);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'label' => false,
'data_class' => $this->em->getEntityName(AddressInterface::class),
]
);
}
}

+ 17
- 0
Resources/translations/admin.fr.yaml Voir le fichier

@@ -28,9 +28,26 @@ setting_definition:

entity:
default:
panels:
address: Adresse
fields:
address: Adresse
merchant: Marchand
taxRate: Règle de taxe
Address:
fields:
type: Type
typeOptions:
legal-person: Professionnel
individual: Particulier
civility: Civilité
zip: Code postal
city: Ville
address: Adresse
phone: Téléphone
company: Entreprise
siret: SIRET
tva: Numero de TVA
Merchant:
label: Marchand
label_plurial: Marchands

Chargement…
Annuler
Enregistrer