Browse Source

Switch symfony 5.4

packProduct
Fabien Normand 2 years ago
parent
commit
728acca771
4 changed files with 79 additions and 48 deletions
  1. +1
    -1
      Controller/Section/SwitchSectionAdminController.php
  2. +62
    -28
      Form/Section/SwitchSectionFormType.php
  3. +14
    -16
      Resources/views/adminlte/layout.html.twig
  4. +2
    -3
      Twig/FormTwigExtension.php

+ 1
- 1
Controller/Section/SwitchSectionAdminController.php View File

@@ -30,7 +30,7 @@ class SwitchSectionAdminController extends AbstractController

// valeur par défaut de $section : Tout afficher
$section = null;
$idSection = $form->get('id_section')->getData();
$idSection = $form->getClickedButton()->getConfig()->getOptions()['attr']['value'];
$userMerchant = $merchantResolver->getUserMerchant();

if($userMerchant) {

+ 62
- 28
Form/Section/SwitchSectionFormType.php View File

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Form\Section;

use App\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
@@ -20,53 +21,86 @@ use Symfony\Component\OptionsResolver\OptionsResolver;

class SwitchSectionFormType extends AbstractType
{
protected EntityManager $em;
protected TranslatorAdmin $translatorAdmin;
protected SectionStore $sectionStore;
protected SectionResolver $sectionResolver;
protected MerchantResolver $merchantResolver;
protected SectionSolver $sectionSolver;

public function __construct(
EntityManager $em,
TranslatorAdmin $translatorAdmin,
SectionResolver $sectionResolver,
SectionSolver $sectionSolver
) {
$this->em = $em;
TranslatorAdmin $translatorAdmin,
SectionStore $sectionStore,
SectionResolver $sectionResolver,
MerchantResolver $merchantResolver,
SectionSolver $sectionSolver
)
{
$this->translatorAdmin = $translatorAdmin;
$this->sectionResolver = $sectionResolver;
$this->sectionStore = $sectionStore;
$this->merchantResolver = $merchantResolver;
$this->sectionSolver = $sectionSolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$section = $options['section'];



// $builder->add(
// 'id_section',
// HiddenType::class,
// [
// 'data' => $section ? $section->getId() : null
// ]
// );




$currentSection = $this->sectionResolver->getCurrent();
$sections = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOnline();

$styleButton = '';
$classButton = 'btn-section';
if (null == $currentSection) {
$classButton .= ' btn-section-current ' . $this->sectionSolver->getHtmlClass($currentSection);
}
//TOUT afficher
$builder->add(
'id_section',
HiddenType::class,
[
'data' => $section ? $section->getId() : null
'switch_all',
SubmitType::class,
[
'label' => 'Tout afficher',
'attr' => [
'class' => $classButton,
'style' => $styleButton,
'value' => null,
]
]
);

$styleButton = '';
$classButton = 'btn-section';
if ($section == $currentSection) {
$classButton .= ' btn-section-current '.$this->sectionSolver->getHtmlClass($currentSection);
}

$builder->add(
'submit',
foreach ($sections as $section) {
$styleButton = '';
$classButton = 'btn-section';
if ($section == $currentSection) {
$classButton .= ' btn-section-current ' . $this->sectionSolver->getHtmlClass($currentSection);
}

$builder->add(
'switch_'.$section->getSlug(),
SubmitType::class,
[
'label' => $section ? $section->getTitle() : 'Tout afficher',
'attr' => [
'class' => $classButton,
'style' => $styleButton,
]
'label' => $section->getTitle(),
'attr' => [
'class' => $classButton,
'style' => $styleButton,
'value' => $section->getId(),
]
]
);
);
}
}

/**
@@ -75,9 +109,9 @@ class SwitchSectionFormType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'section' => null,
]
[
'section' => null,
]
);
}


+ 14
- 16
Resources/views/adminlte/layout.html.twig View File

@@ -8,18 +8,10 @@

<nav class="carac navbar navbar-expand navbar-light main-header{% if is_display_switch_section %} display-section-switch {{ section_container.solver.getHtmlClass(section_current()) }}{% endif %}">

{% if is_display_switch_section %}
<ul class="navbar-nav left">
<li class="nav-item d-none d-sm-inline-block">
{{ _self.form_switch_section(null) }}
</li>
{% for section in carac_sections() %}
<li class="nav-item d-none d-sm-inline-block">
{{ _self.form_switch_section(section) }}
</li>
{% endfor %}
</ul>
{% endif %}
{% if is_display_switch_section %}
{{ _self.form_switch_section() }}
{% endif %}

<ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i>
@@ -47,14 +39,20 @@

{% if(user.favoriteMerchant != merchant_current) %}
{# modal affichée uniquement si la sessionStorage.visit_merchant n'est pas défini (js) #}
{% include '@LcCaracole/admin/merchant/modal/switch_merchant.html.twig' %}
{% include '@LcCaracole/admin/merchant/modal/switch_merchant.html.twig' %}
{% endif %}
{% endblock %}

{% macro form_switch_section(section) %}
{% set form_switch_section = carac_form_switch_section(section) %}
{% macro form_switch_section() %}
{% set form_switch_section = carac_form_switch_section() %}
{% form_theme form_switch_section '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_section) }}
{{ form(form_switch_section) }}
<ul class="navbar-nav left">
{% for field in form_switch_section %}
<li class="nav-item d-none d-sm-inline-block">
{{ form_row(field) }}
</li>
{% endfor %}
</ul>
{{ form_end(form_switch_section) }}
{% endmacro %}

+ 2
- 3
Twig/FormTwigExtension.php View File

@@ -45,15 +45,14 @@ class FormTwigExtension extends AbstractExtension
return $form->createView();
}

public function getFormSwitchSection($section)
public function getFormSwitchSection()
{
$form = $this->formFactory->create(
SwitchSectionFormType::class,
null,
[
'action' => $this->urlGenerator->generate('admin_section_switch'),
'attr' => ['class' => 'switch-section'],
'section' => $section,
'attr' => ['class' => 'switch-section']
]
);
return $form->createView();

Loading…
Cancel
Save