You are here

public function LingotekConfigurationService::shouldFieldLingotekEnabled in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8.2 src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  2. 3.0.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  3. 3.1.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  4. 3.2.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  5. 3.3.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  6. 3.4.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  7. 3.5.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  8. 3.6.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  9. 3.7.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()
  10. 3.8.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::shouldFieldLingotekEnabled()

File

src/LingotekConfigurationService.php, line 331

Class

LingotekConfigurationService
Service for managing lingotek configuration.

Namespace

Drupal\lingotek

Code

public function shouldFieldLingotekEnabled($entity_type_id, $bundle, $field_name) {
  $should = FALSE;
  $field_definitions = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions($entity_type_id, $bundle);
  $config = \Drupal::config('lingotek.settings');
  $key = 'translate.entity.' . $entity_type_id . '.' . $bundle . '.field.' . $field_name;
  $saved_value = $config
    ->get($key);
  $default_enabled = [
    'string',
    'image',
    'text',
    'text_with_summary',
    'text_long',
    'string_long',
    'path',
    'entity_reference_revisions',
    'cohesion_entity_reference_revisions',
  ];
  if ($saved_value === NULL) {
    $type = $field_definitions[$field_name]
      ->getType();
    $should = !empty($field_definitions[$field_name]) && in_array($type, $default_enabled);
  }
  return $should;
}