public function EntityTranslationDefaultHandler::removeTranslation in Entity Translation 7
Overrides EntityTranslationHandlerInterface::removeTranslation
See also
EntityTranslationHandlerInterface::removeTranslation()
2 calls to EntityTranslationDefaultHandler::removeTranslation()
File
- includes/
translation.handler.inc, line 720 - Default translation handler for the translation module.
Class
- EntityTranslationDefaultHandler
- Class implementing the default entity translation behaviours.
Code
public function removeTranslation($langcode) {
$translations_key = $this
->getTranslationsKey();
if (empty($translations_key)) {
return;
}
$hook_info = array(
'hook' => 'delete',
);
if (!empty($langcode)) {
unset($this->entity->{$translations_key}->data[$langcode]);
// Keep track that the current translation has been removed.
$this->entity->{$translations_key}->hook[$langcode] = $hook_info;
}
elseif (!empty($this->entity->{$translations_key}->data)) {
$keys = array_keys($this->entity->{$translations_key}->data);
$values = array_fill(0, count($keys), $hook_info);
// Keep track that the all translations have been removed.
$this->entity->{$translations_key}->hook = array_combine($keys, $values);
// Actually remove translations.
$this->entity->{$translations_key}->data = array();
}
// Remove field translations.
foreach (field_info_instances($this->entityType, $this->bundle) as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
if ($field['translatable']) {
if (!empty($langcode)) {
$this->entity->{$field_name}[$langcode] = array();
}
else {
$this->entity->{$field_name} = array();
}
}
}
// Clear the cache for this entity.
entity_get_controller($this->entityType)
->resetCache(array(
$this
->getEntityId(),
));
}