diff --git a/core/modules/system/lib/Drupal/system/DateFormatStorageController.php b/core/modules/system/lib/Drupal/system/DateFormatStorageController.php deleted file mode 100644 index b3d5571..0000000 --- a/core/modules/system/lib/Drupal/system/DateFormatStorageController.php +++ /dev/null @@ -1,53 +0,0 @@ -getLocales() as $langcode) { - if (isset($languages[$langcode])) { - config('locale.config.' . $langcode . '.system.date_format.' . $entity->id()) - ->setData($entity->getExportProperties()) - ->save(); - } - } - } - - /** - * {inheritdoc} - */ - protected function postDelete($entities) { - parent::postDelete($entities); - - // Clean up the localized entry if required. - if (module_exists('language')) { - $languages = language_list(); - foreach ($entities as $entity) { - $format_id = $entity->id(); - foreach ($languages as $langcode => $data) { - config("locale.config.$langcode.system.date_format.$format_id")->delete(); - } - } - } - } - -} diff --git a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php index 1f25c01..94f52d3 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Datetime\DrupalDateTime; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\system\DateFormatInterface; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; @@ -21,7 +22,7 @@ * label = @Translation("Date format"), * module = "system", * controllers = { - * "storage" = "Drupal\system\DateFormatStorageController", + * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "access" = "Drupal\system\DateFormatAccessController", * "list" = "Drupal\system\DateFormatListController", * "form" = { @@ -162,4 +163,39 @@ public function isLocked() { return (bool) $this->locked; } + /** + * {@inheritdoc} + */ + public function preSave(EntityStorageControllerInterface $storage_controller) { + if ($this->hasLocales()) { + $config_factory = \Drupal::service('config.factory'); + $properties = $this->getExportProperties(); + $languages = language_list(); + // Check if the suggested language codes are configured. + foreach ($this->getLocales() as $langcode) { + if (isset($languages[$langcode])) { + $config_factory->get('locale.config.' . $langcode . '.system.date_format.' . $this->id()) + ->setData($properties) + ->save(); + } + } + } + } + + /** + * {@inheritdoc} + */ + public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) { + // Clean up the localized entry if required. + if (\Drupal::moduleHandler()->moduleExists('language')) { + $languages = language_list(); + foreach ($entities as $entity) { + $format_id = $entity->id(); + foreach ($languages as $langcode => $data) { + config("locale.config.$langcode.system.date_format.$format_id")->delete(); + } + } + } + } + }