You are here

protected function EntityTranslationUnifiedFormInlineMode::alterTitle in Entity Translation Unified Form 8

Helper function to add the language label to a title.

2 calls to EntityTranslationUnifiedFormInlineMode::alterTitle()
EntityTranslationUnifiedFormInlineMode::fieldFormAlter in src/Plugin/EntityTranslationUnifiedFormMode/EntityTranslationUnifiedFormInlineMode.php
EntityTranslationUnifiedFormTabbedMode::fieldFormAlter in src/Plugin/EntityTranslationUnifiedFormMode/EntityTranslationUnifiedFormTabbedMode.php

File

src/Plugin/EntityTranslationUnifiedFormMode/EntityTranslationUnifiedFormInlineMode.php, line 30

Class

EntityTranslationUnifiedFormInlineMode
@EntityTranslationUnifiedFormMode ( id = "EntityTranslationUnifiedFormInlineMode", admin_label = Plugin annotation @Translation("Inline Mode"), )

Namespace

Drupal\entity_translation_unified_form\Plugin\EntityTranslationUnifiedFormMode

Code

protected function alterTitle($form, $form_state, &$field, $field_name, $language) {
  if (!isset($field['widget']) || !is_object($language)) {
    return;
  }

  // Get language display mode
  $form_object = $form_state
    ->getFormObject();
  $entity = $form_object
    ->getEntity();
  $entity_type_id = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  $language_display = entity_translation_unified_form_language_display($entity_type_id, $bundle);
  if ($language_display == 'native') {

    // Get native languages.
    $language_manager = \Drupal::languageManager();
    $native_languages = $language_manager
      ->getNativeLanguages();
    $current_language = $native_languages[$language
      ->getId()];

    // Get language name in its own language.
    $text = ' (' . t($current_language
      ->getName(), [], [
      'langcode' => $language
        ->getId(),
    ]) . ')';
  }
  elseif ($language_display == 'current') {
    $text = ' (' . t($language
      ->getName()) . ')';
  }
  else {
    $text = ' (' . $language
      ->getId() . ')';
  }
  $widget =& $field['widget'];
  $this
    ->addTranslatabilityClue($widget, $text);
}