protected function InlineParagraphsWidget::initIsTranslating

Initializes the translation form state.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state:

\Drupal\Core\Entity\EntityInterface $host:

2 calls to InlineParagraphsWidget::initIsTranslating()
InlineParagraphsWidget::formElement in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Uses a similar approach to populate a new translation.
InlineParagraphsWidget::formMultipleElements in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1380

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function initIsTranslating(FormStateInterface $form_state, EntityInterface $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 (isset($langcode) && $host
    ->hasTranslation($langcode) && $host
    ->getTranslation($langcode)
    ->get($default_langcode_key)->value == 0) {

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