public static function ParagraphsSets::inTranslation in Paragraphs Sets 8.2
Check if form state is in translation.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: Form state.
\Drupal\Core\Entity\EntityInterface $host: The host entity.
Return value
bool TRUE if the form state is in translation mode, FALSE otherwise.
File
- src/
ParagraphsSets.php, line 329
Class
- ParagraphsSets
- Utitlity class for paragraphs_sets.
Namespace
Drupal\paragraphs_setsCode
public static function inTranslation(FormStateInterface $form_state, EntityInterface $host) {
$is_in_translation = FALSE;
if (!$host
->isTranslatable()) {
return FALSE;
}
if (!$host
->getEntityType()
->hasKey('default_langcode')) {
return FALSE;
}
$default_langcode_key = $host
->getEntityType()
->getKey('default_langcode');
if (!$host
->hasField($default_langcode_key)) {
return FALSE;
}
if (!empty($form_state
->get('content_translation'))) {
// Adding a language through the ContentTranslationController.
$is_in_translation = TRUE;
}
if ($host
->hasTranslation($form_state
->get('langcode')) && $host
->getTranslation($form_state
->get('langcode'))
->get($default_langcode_key)->value == 0) {
// Editing a translation.
$is_in_translation = TRUE;
}
return $is_in_translation;
}