You are here

public function EntityOperations::entityTranslationDelete in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::entityTranslationDelete()

Parameters

\Drupal\Core\Entity\EntityInterface $translation: The entity translation being deleted.

See also

hook_entity_translation_delete()

File

core/modules/content_moderation/src/EntityOperations.php, line 256

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\content_moderation

Code

public function entityTranslationDelete(EntityInterface $translation) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */
  if (!$translation
    ->isDefaultTranslation()) {
    $langcode = $translation
      ->language()
      ->getId();
    $content_moderation_state = ContentModerationStateEntity::loadFromModeratedEntity($translation);
    if ($content_moderation_state && $content_moderation_state
      ->hasTranslation($langcode)) {
      $content_moderation_state
        ->removeTranslation($langcode);
      ContentModerationStateEntity::updateOrCreateFromEntity($content_moderation_state);
    }
  }
}