You are here

function entity_translation_unified_form_add_fields in Entity Translation Unified Form 8

Same name and namespace in other branches
  1. 7 entity_translation_unified_form.module \entity_translation_unified_form_add_fields()

Add opposite-language ET fields to a form.

1 call to entity_translation_unified_form_add_fields()
entity_translation_unified_form_form_alter in ./entity_translation_unified_form.module
Add language fields to node forms.

File

./entity_translation_unified_form.module, line 535

Code

function entity_translation_unified_form_add_fields(&$form, FormStateInterface $form_state) {
  $form_state
    ->loadInclude('entity_translation_unified_form', 'inc', 'entity_translation_unified_form.theme');
  $form_object = $form_state
    ->getFormObject();
  if ($form_object instanceof EntityForm) {
    $entity = $form_object
      ->getEntity();
    $entity_type = $entity
      ->getEntityTypeId();
    $bundle = $entity
      ->bundle();
    $entityManager = \Drupal::service('entity_field.manager');
    $fields = $entityManager
      ->getFieldDefinitions($entity_type, $bundle);
    $mode_plugin_id = entity_translation_unified_form_bundle_display_mode($entity_type, $bundle);
    if ($mode_plugin_id != NULL) {

      // If side-by-side selected only Inline plugin is allowed (note: should be treated at config level, not here)
      $sbs = entity_translation_unified_form_sbs_enabled($entity_type, $bundle);
      if ($sbs) {
        $mode_plugin_id = 'EntityTranslationUnifiedFormInlineMode';
      }
      $mode_plugin = entity_translation_unified_form_get_mode_plugin($mode_plugin_id);

      // Process each of the entity type's fields.
      foreach ($fields as $field_name => $field_definition) {
        entity_translation_unified_form_node_insert_other_language_fields($form, $form_state, $field_definition, $mode_plugin);
      }
    }
  }
}