public function MessageTemplate::preSave in Message 8
Acts on an entity before the presave hook is invoked.
Used before the entity is saved and before invoking the presave hook.
Ensure that config entities which are bundles of other entities cannot have their ID changed.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
Throws
\Drupal\Core\Config\ConfigNameException Thrown when attempting to rename a bundle entity.
Overrides ConfigEntityBundleBase::preSave
File
- src/
Entity/ MessageTemplate.php, line 325
Class
- MessageTemplate
- Defines the Message template entity class.
Namespace
Drupal\message\EntityCode
public function preSave(EntityStorageInterface $storage) {
// Don't do anything during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
$this->text = array_filter($this->text, function ($partial) {
// Filter out any partials with an empty `value`.
return !empty($partial['value']);
});
$language_manager = \Drupal::languageManager();
if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
// Set the values for the default site language.
$config_translation = $language_manager
->getLanguageConfigOverride($language_manager
->getDefaultLanguage()
->getId(), 'message.template.' . $this
->id());
$config_translation
->set('text', $this->text);
$config_translation
->save();
}
parent::preSave($storage);
}