You are here

protected function InlineParagraphsWidget::initIsTranslating in Paragraphs 8

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

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1363

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

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