You are here

protected function EntityReferenceLayoutWidget::initIsTranslating in Entity Reference with Layout 8

Determine if widget is in translation.

Initializes $this->isTranslating.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

\Drupal\Core\Entity\ContentEntityInterface $host: The host entity.

1 call to EntityReferenceLayoutWidget::initIsTranslating()
EntityReferenceLayoutWidget::formMultipleElements in src/Plugin/Field/FieldWidget/EntityReferenceLayoutWidget.php
Builds the main widget form array container/wrapper.

File

src/Plugin/Field/FieldWidget/EntityReferenceLayoutWidget.php, line 1400

Class

EntityReferenceLayoutWidget
Entity Reference with Layout field widget.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldWidget

Code

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;
  }
  if (!empty($form_state
    ->get('content_translation'))) {

    // Adding a language through the ContentTranslationController.
    $this->isTranslating = TRUE;
  }
  $langcode = $form_state
    ->get('langcode');
  if ($host
    ->hasTranslation($langcode) && $host
    ->getTranslation($langcode)
    ->get($default_langcode_key)->value == 0) {

    // Editing a translation.
    $this->isTranslating = TRUE;
  }
}