You are here

protected function RadioactivityReferenceWidget::initIsTranslating in Radioactivity 4.0.x

Initializes the translation form state.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: Form state object.

\Drupal\Core\Entity\EntityInterface $host: Host entity of the field.

1 call to RadioactivityReferenceWidget::initIsTranslating()
RadioactivityReferenceWidget::formElement in src/Plugin/Field/FieldWidget/RadioactivityReferenceWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/RadioactivityReferenceWidget.php, line 132

Class

RadioactivityReferenceWidget
Plugin implementation of the 'radioactivity_reference' widget.

Namespace

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