function ContentEntityBase::removeTranslation
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::removeTranslation()
- 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::removeTranslation()
- 11.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::removeTranslation()
File
-
core/
lib/ Drupal/ Core/ Entity/ ContentEntityBase.php, line 971
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
public function removeTranslation($langcode) {
if (isset($this->translations[$langcode]) && $langcode != LanguageInterface::LANGCODE_DEFAULT && $langcode != $this->defaultLangcode) {
foreach ($this->getFieldDefinitions() as $name => $definition) {
if ($definition->isTranslatable()) {
unset($this->values[$name][$langcode]);
unset($this->fields[$name][$langcode]);
}
}
// If removing a translation which has not been saved yet, then we have
// to remove it completely so that ::getTranslationStatus returns the
// proper status.
if ($this->translations[$langcode]['status'] == static::TRANSLATION_CREATED) {
unset($this->translations[$langcode]);
}
else {
if ($this->translations[$langcode]['status'] == static::TRANSLATION_EXISTING) {
$this->translations[$langcode]['status_existed'] = TRUE;
}
$this->translations[$langcode]['status'] = static::TRANSLATION_REMOVED;
}
}
else {
throw new \InvalidArgumentException("The specified translation ({$langcode}) cannot be removed.");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.