protected function ParagraphsWidget::initIsTranslating

Determine if widget is in translation.

Initializes $this->isTranslating.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state:

\Drupal\Core\Entity\ContentEntityInterface $host:

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

File

paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2708

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\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;
  }

  // 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;
  }
}