Преглед на файлове

[Backend] Optimistation de FieldDefinition #169

develop
Fabien Normand преди 1 година
родител
ревизия
a2fd6916f4
променени са 4 файла, в които са добавени 34 реда и са изтрити 12 реда
  1. +7
    -2
      Definition/Field/FieldDefinitionTrait.php
  2. +6
    -2
      Definition/Field/Product/ProductCategoryFieldDefinition.php
  3. +6
    -2
      Definition/Field/Site/NewsFieldDefinition.php
  4. +15
    -6
      Definition/Field/User/UserFieldDefinition.php

+ 7
- 2
Definition/Field/FieldDefinitionTrait.php Целия файл

@@ -12,14 +12,19 @@ trait FieldDefinitionTrait
use MerchantContextTrait;
use SectionContextTrait;

protected ?array $sectionArray = null;

public function configureFieldsBase(): array
{
$sectionArray = $this->sectionStore->setMerchant($this->merchant)->get();
if(is_null($this->sectionArray)){
$this->sectionArray = $this->sectionStore->setMerchant($this->merchant)->get();
}


return array_merge(parent::configureFieldsBase(), [
'section' => AssociationField::new('section')
->setTemplatePath('@LcCaracole/admin/section/field/section.html.twig')
->setFormTypeOption('choices', $sectionArray)
->setFormTypeOption('choices', $this->sectionArray)
]);
}


+ 6
- 2
Definition/Field/Product/ProductCategoryFieldDefinition.php Целия файл

@@ -18,6 +18,8 @@ class ProductCategoryFieldDefinition extends AbstractFieldDefinition
protected SectionStore $sectionStore;
protected ProductCategoryStore $productCategoryStore;

protected ?array $productCategoryArray = null;

public function __construct(
TranslatorAdmin $translatorAdmin,
SectionStore $sectionStore,
@@ -70,15 +72,17 @@ class ProductCategoryFieldDefinition extends AbstractFieldDefinition

public function configureFields(): array
{
$productCategoryArray = $this->productCategoryStore
if(is_null($this->productCategoryArray)) {
$this->productCategoryArray = $this->productCategoryStore
->setSection($this->section)
->getParents();
}

return [
'title' => TextField::new('title')->setSortable(true),
'position' => NumberField::new('position')->setSortable(true),
'parent' => AssociationField::new('parent')
->setFormTypeOption('choices', $productCategoryArray)
->setFormTypeOption('choices', $this->productCategoryArray)
->setFormTypeOption(
'choice_label',
function ($productCategory) {

+ 6
- 2
Definition/Field/Site/NewsFieldDefinition.php Целия файл

@@ -12,6 +12,8 @@ class NewsFieldDefinition extends SovNewsFieldDefinition
{
use FieldDefinitionTrait;

protected ?array $newsletterArray = null;

protected SectionStore $sectionStore;
protected NewsletterStore $newsletterStore;

@@ -36,12 +38,14 @@ class NewsFieldDefinition extends SovNewsFieldDefinition
{
$fieldArray = parent::configureFields();

$newsletterArray = $this->newsletterStore
if(is_null($this->newsletterArray)){
$this->newsletterArray = $this->newsletterStore
->setSection($this->section)
->setMerchant($this->merchant)
->get();
}

$fieldArray['newsletter']->setFormTypeOption('choices', $newsletterArray);
$fieldArray['newsletter']->setFormTypeOption('choices', $this->newsletterArray);

return $fieldArray;
}

+ 15
- 6
Definition/Field/User/UserFieldDefinition.php Целия файл

@@ -21,15 +21,19 @@ class UserFieldDefinition extends SovUserFieldDefinition
{
use MerchantContextTrait;

protected ?array $newsletterArray = null;
protected ?array $groupUserArray = null;

protected GroupUserStore $groupUserStore;
protected NewsletterStore $newsletterStore;

public function __construct(
TranslatorAdmin $translatorAdmin,
RolesDefinition $rolesDefinition,
GroupUserStore $groupUserStore,
GroupUserStore $groupUserStore,
NewsletterStore $newsletterStore
) {
)
{
parent::__construct($translatorAdmin, $rolesDefinition);

$this->groupUserStore = $groupUserStore;
@@ -70,19 +74,24 @@ class UserFieldDefinition extends SovUserFieldDefinition

public function configureFields(): array
{
$groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll();
$newsletters = $this->newsletterStore->getAll();
if (is_null($this->newsletterArray)) {
$this->newsletterArray = $this->newsletterStore->getAll();
}

if (is_null($this->groupUserArray)) {
$this->groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->getAll();
}

return array_merge(parent::configureFields(), [
'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
'newsletters' => AssociationField::new('newsletters')
->setFormTypeOption('choices', $newsletters)
->setFormTypeOption('choices', $this->newsletterArray)
->setFormTypeOption('choice_label', function ($choice) {
return $choice->getTitle() . '[' . $choice->getSection()->getMerchant() . ']';
})
->setSortable(true),
'groupUsers' => AssociationField::new('groupUsers')
->setFormTypeOption('choices', $groupUsers)
->setFormTypeOption('choices', $this->groupUserArray)
->setCustomOption('class', GroupUser::class)
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choice_label', function ($choice) {

Loading…
Отказ
Запис