diff --git a/core/lib/Drupal/Core/Form/ConfigFormBase.php b/core/lib/Drupal/Core/Form/ConfigFormBase.php index 7363048..8ed7403 100644 --- a/core/lib/Drupal/Core/Form/ConfigFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfigFormBase.php @@ -17,22 +17,13 @@ abstract class ConfigFormBase extends FormBase { /** - * The config factory. - * - * This property is redeclared so it can be used directly by this class. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - private $configFactory; - - /** * Constructs a \Drupal\system\ConfigFormBase object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. */ public function __construct(ConfigFactoryInterface $config_factory) { - $this->configFactory = $config_factory; + $this->setConfigFactory($config_factory); } /** @@ -76,10 +67,12 @@ public function submitForm(array &$form, array &$form_state) { * configuration. */ protected function config($name) { - $old_state = $this->configFactory->getOverrideState(); - $this->configFactory->setOverrideState(FALSE); - $config = $this->configFactory->get($name); - $this->configFactory->setOverrideState($old_state); + $config_factory = $this->configFactory(); + $old_state = $config_factory->getOverrideState(); + $config_factory->setOverrideState(FALSE); + $config = $config_factory->get($name); + $config_factory->setOverrideState($old_state); return $config; } + } diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 0ca8e03..cd377d7 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -126,10 +126,19 @@ protected function translationManager() { * A configuration object. */ protected function config($name) { + return $this->configFactory()->get($name); + } + + /** + * Gets the config factory for this form. + * + * @return \Drupal\Core\Config\ConfigFactoryInterface + */ + protected function configFactory() { if (!$this->configFactory) { $this->configFactory = $this->container()->get('config.factory'); } - return $this->configFactory->get($name); + return $this->configFactory; } /** diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php index ee89f07..fb3ba88 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php @@ -9,7 +9,6 @@ use Drupal\config_translation\ConfigMapperManagerInterface; use Drupal\Core\Config\Config; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Schema\Element; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -84,15 +83,6 @@ protected $sourceLanguage; /** - * The config factory. - * - * This property is redeclared so it can be used directly by this class. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - private $configFactory; - - /** * An array of base language configuration data keyed by configuration names. * * @var array @@ -110,15 +100,12 @@ * The translation storage object. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. */ - public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager) { + public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) { $this->typedConfigManager = $typed_config_manager; $this->configMapperManager = $config_mapper_manager; $this->localeStorage = $locale_storage; $this->moduleHandler = $module_handler; - $this->configFactory = $config_factory; $this->languageManager = $language_manager; } @@ -131,7 +118,6 @@ public static function create(ContainerInterface $container) { $container->get('plugin.manager.config_translation.mapper'), $container->get('locale.storage'), $container->get('module_handler'), - $container->get('config.factory'), $container->get('language_manager') ); } @@ -185,10 +171,11 @@ public function buildForm(array $form, array &$form_state, Request $request = NU // Get base language configuration to display in the form before setting the // language to use for the form. This avoids repetitively settings and // resetting the language to get original values later. - $old_state = $this->configFactory->getOverrideState(); - $this->configFactory->setOverrideState(FALSE); + $config_factory = $this->configFactory(); + $old_state = $config_factory->getOverrideState(); + $config_factory->setOverrideState(FALSE); $this->baseConfigData = $this->mapper->getConfigData(); - $this->configFactory->setOverrideState($old_state); + $config_factory->setOverrideState($old_state); // Set the translation target language on the configuration factory. $original_language = $this->languageManager->getConfigOverrideLanguage(); @@ -207,7 +194,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU ); foreach ($this->mapper->getConfigNames() as $name) { $form['config_names'][$name] = array('#type' => 'container'); - $form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $this->config($name)->get(), $this->baseConfigData[$name]); + $form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $config_factory->get($name)->get(), $this->baseConfigData[$name]); } $form['actions']['#type'] = 'actions'; @@ -230,12 +217,13 @@ public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']['config_names']; // For the form submission handling, use the raw data. - $old_state = $this->configFactory->getOverrideState(); - $this->configFactory->setOverrideState(FALSE); + $config_factory = $this->configFactory(); + $old_state = $config_factory->getOverrideState(); + $config_factory->setOverrideState(FALSE); foreach ($this->mapper->getConfigNames() as $name) { // Set configuration values based on form submission and source values. - $base_config = $this->config($name); + $base_config = $config_factory->get($name); $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->id, $name); $locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $name)); @@ -250,7 +238,7 @@ public function submitForm(array &$form, array &$form_state) { $config_translation->save(); } } - $this->configFactory->setOverrideState($old_state); + $config_factory->setOverrideState($old_state); $form_state['redirect_route'] = array( 'route_name' => $this->mapper->getOverviewRoute(),