public function ContentEntityBase::removeTranslation

public ContentEntityBase::removeTranslation($langcode)

Removes the translation identified by the given language code.

Parameters

string $langcode: The language code identifying the translation to be removed.

Overrides TranslatableInterface::removeTranslation

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 839

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

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]);
      }
    }
    $this->translations[$langcode]['status'] = static::TRANSLATION_REMOVED;
  }
  else {
    throw new \InvalidArgumentException("The specified translation ($langcode) cannot be removed.");
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityBase.php/function/ContentEntityBase::removeTranslation/8.1.x