You are here

protected function ParagraphsWidget::initIsTranslating in Paragraphs 8

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 src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Uses a similar approach to populate a new translation.
ParagraphsWidget::formMultipleElements in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Special handling to create form elements for multiple values.

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2359

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 ($host
    ->hasTranslation($langcode) && $host
    ->getTranslation($langcode)
    ->get($default_langcode_key)->value == 0) {

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