You are here

protected function LayoutParagraphsWidget::initIsTranslating in Layout Paragraphs 1.0.x

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 LayoutParagraphsWidget::initIsTranslating()
LayoutParagraphsWidget::formMultipleElements in src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php
Builds the main widget form array container/wrapper.

File

src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php, line 2381

Class

LayoutParagraphsWidget
Entity Reference with Layout field widget.

Namespace

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