entityManager = $entityManager; $this->settingSolver = $settingSolver; $this->siteStore = $siteStore; $this->siteSettingDefinition = $siteSettingDefinition; $this->siteSettingFactory = $siteSettingFactory; } public function initSiteSettings() { $site = $this->siteStore->getOneByDevAlias('default'); if ($site) { $settings = $this->siteSettingDefinition->getSettings(); foreach ($settings as $category => $settingList) { foreach ($settingList as $settingName => $setting) { $entitySetting = $this->settingSolver->getSetting($site, $settingName); if (!$entitySetting) { $text = null; $date = null; $file = null; $fieldValue = isset($setting['default']) ? $setting['default'] : null; if ($setting['field'] == 'text') { $text = $fieldValue; } if ($setting['field'] == 'date') { $date = $fieldValue; } if ($setting['field'] == 'file') { $file = $fieldValue; } $entitySetting = $this->siteSettingFactory->create( $site, $setting['name'], $text, $date, $file ); $this->entityManager->create($entitySetting); } else { $methodGetValue = 'get' . ucfirst($setting['field']); if ($entitySetting->$methodGetValue() === null && isset($setting['default']) && $setting['default'] !== null) { $methodSetValue = 'set' . ucfirst($setting['field']); $entitySetting->$methodSetValue($setting['default']); $this->entityManager->update($entitySetting); } } } } $this->entityManager->flush(); } else { throw new NotFoundHttpException('Le site par défaut n\'existe pas.'); } } }