Browse Source

SettingEventSubscriber : prise en compte des valeurs par défaut par section

packProduct
Guillaume 3 years ago
parent
commit
38bb7d320a
3 changed files with 20 additions and 9 deletions
  1. +12
    -7
      EventSubscriber/SettingEventSubscriber.php
  2. +1
    -0
      Factory/Section/SectionFactory.php
  3. +7
    -2
      Factory/Setting/SectionSettingFactory.php

+ 12
- 7
EventSubscriber/SettingEventSubscriber.php View File

$date = null; $date = null;
$file = null; $file = null;


$fieldValue = isset($setting['default']) ? $setting['default'] : null;
$valueDefault = isset($setting['default']) ? $this->settingSolver->getDefaultValue($entity, $setting['default']) : null;


if ($setting['field'] == 'text') { if ($setting['field'] == 'text') {
$text = $fieldValue;
$text = $valueDefault;
} elseif ($setting['field'] == 'date') { } elseif ($setting['field'] == 'date') {
$date = $fieldValue;
$date = $valueDefault;
} elseif ($setting['field'] == 'file') { } elseif ($setting['field'] == 'file') {
$file = $fieldValue;
$file = $valueDefault;
} }


$entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file); $entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file);
if ($this->settingSolver->getValue($entitySetting) === null if ($this->settingSolver->getValue($entitySetting) === null
&& isset($setting['default']) && isset($setting['default'])
&& $setting['default'] !== null) { && $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->entityManager->update($entitySetting);

$valueDefault = $this->settingSolver->getDefaultValue($entity, $setting['default']);

if($valueDefault) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($valueDefault);
$this->entityManager->update($entitySetting);
}
} }
} }
} }

+ 1
- 0
Factory/Section/SectionFactory.php View File

$section = new Section(); $section = new Section();


$section->setMerchant($merchant); $section->setMerchant($merchant);
$section->setStatus(1);


return $section; return $section;
} }

+ 7
- 2
Factory/Setting/SectionSettingFactory.php View File

class SectionSettingFactory extends AbstractFactory class SectionSettingFactory extends AbstractFactory
{ {


public function create(SectionInterface $section, string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
{
public function create(
SectionInterface $section,
string $name,
string $text = null,
\DateTime $date = null,
FileInterface $file = null
) {
$merchantSetting = new SectionSetting(); $merchantSetting = new SectionSetting();


$merchantSetting->setSection($section); $merchantSetting->setSection($section);

Loading…
Cancel
Save