Determine if widget is in translation.
Initializes $this->isTranslating.
\Drupal\Core\Form\FormStateInterface $form_state:
\Drupal\Core\Entity\ContentEntityInterface $host:
protected function initIsTranslating(FormStateInterface $form_state, ContentEntityInterface $host) {
if ($this->isTranslating != NULL) {
return;
}
$this->isTranslating = FALSE;
if (!$host
->isTranslatable()) {
return;
}
if (!$host
->getEntityType()
->hasKey('default_langcode')) {
return;
}
$default_langcode_key = $host
->getEntityType()
->getKey('default_langcode');
if (!$host
->hasField($default_langcode_key)) {
return;
}
// Supporting \Drupal\content_translation\Controller\ContentTranslationController.
if (!empty($form_state
->get('content_translation'))) {
// Adding a translation.
$this->isTranslating = TRUE;
}
$langcode = $form_state
->get('langcode');
if (isset($langcode) && $host
->hasTranslation($langcode) && $host
->getTranslation($langcode)
->get($default_langcode_key)->value == 0) {
// Editing a translation.
$this->isTranslating = TRUE;
}
}