You are here

protected function LingotekSettingsTabContentForm::retrieveFields in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  2. 4.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  3. 3.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  4. 3.1.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  5. 3.2.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  6. 3.3.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  7. 3.4.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  8. 3.5.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  9. 3.6.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  10. 3.7.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
  11. 3.8.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::retrieveFields()
1 call to LingotekSettingsTabContentForm::retrieveFields()
LingotekSettingsTabContentForm::buildForm in src/Form/LingotekSettingsTabContentForm.php
Form constructor.

File

src/Form/LingotekSettingsTabContentForm.php, line 215
Contains \Drupal\lingotek\Form\LingotekSettingsTabContentForm.

Class

LingotekSettingsTabContentForm
Configure Lingotek

Namespace

Drupal\lingotek\Form

Code

protected function retrieveFields($entity_id, $bundle_id) {
  $entity_type = \Drupal::entityManager()
    ->getDefinition($entity_id);

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');
  $content_translation_manager = \Drupal::service('content_translation.manager');
  $storage_definitions = \Drupal::entityManager()
    ->getFieldStorageDefinitions($entity_id);
  $field_checkboxes = array();
  if ($content_translation_manager
    ->isSupported($entity_id)) {
    $fields = \Drupal::entityManager()
      ->getFieldDefinitions($entity_id, $bundle_id);

    // Find which fields the user previously selected
    foreach ($fields as $field_id => $field_definition) {
      $checkbox_choice = 0;

      // We allow non-translatable entity_reference_revisions fields through.
      // See https://www.drupal.org/node/2788285
      if (!empty($storage_definitions[$field_id]) && $storage_definitions[$field_id]
        ->getProvider() != 'content_translation' && !in_array($storage_definitions[$field_id]
        ->getName(), [
        $entity_type
          ->getKey('langcode'),
        $entity_type
          ->getKey('default_langcode'),
        'revision_translation_affected',
      ]) && ($field_definition
        ->isTranslatable() || ($field_definition
        ->getType() == 'entity_reference_revisions' || $field_definition
        ->getType() == 'path')) && !$field_definition
        ->isComputed() && !$field_definition
        ->isReadOnly()) {
        if ($value = $lingotek_config
          ->isFieldLingotekEnabled($entity_id, $bundle_id, $field_id)) {
          $checkbox_choice = $value;
        }
        $field_checkbox = array(
          '#type' => 'checkbox',
          '#title' => $field_definition
            ->getLabel(),
          '#default_value' => $checkbox_choice,
        );
        $field_checkboxes[$field_id] = $field_checkbox;

        // Display the column translatability configuration widget.
        module_load_include('inc', 'content_translation', 'content_translation.admin');
        $column_element = content_translation_field_sync_widget($field_definition);
        if ($column_element) {
          $properties_checkbox_choice = $lingotek_config
            ->getFieldPropertiesLingotekEnabled($entity_id, $bundle_id, $field_id);
          $field_checkbox = array(
            '#type' => 'checkboxes',
            '#options' => $column_element['#options'],
            '#default_value' => $properties_checkbox_choice ?: [],
            '#attributes' => [
              'class' => array(
                'field-property-checkbox',
              ),
            ],
          );
          $field_checkboxes[$field_id . ':properties'] = $field_checkbox;
        }
      }
      elseif ($field_definition
        ->getType() == 'path' && $field_definition
        ->isComputed()) {
        if ($value = $lingotek_config
          ->isFieldLingotekEnabled($entity_id, $bundle_id, $field_id)) {
          $checkbox_choice = $value;
        }
        $field_checkbox = array(
          '#type' => 'checkbox',
          '#title' => $field_definition
            ->getLabel(),
          '#default_value' => $checkbox_choice,
        );
        $field_checkboxes[$field_id] = $field_checkbox;
      }
    }
  }
  return $field_checkboxes;
}