content_translation_form_field_config_edit_form_alter

content_translation_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state)

Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.

File

core/modules/content_translation/content_translation.module, line 373
Allows entities to be translated into different languages.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function content_translation_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state) {
  $field = $form_state->getFormObject()->getEntity();
  $bundle_is_translatable = \Drupal::service('content_translation.manager')->isEnabled($field->getTargetEntityTypeId(), $field->getTargetBundle());
 
  $form['translatable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Users may translate this field'),
    '#default_value' => $field->isTranslatable(),
    '#weight' => -1,
    '#disabled' => !$bundle_is_translatable,
    '#access' => $field->getFieldStorageDefinition()->isTranslatable(),
  );
 
  // Provide helpful pointers for administrators.
  if (\Drupal::currentUser()->hasPermission('administer content translation') && !$bundle_is_translatable) {
    $toggle_url = \Drupal::url('language.content_settings_page', array(), array(
      'query' => \Drupal::destination()->getAsArray(),
    ));
    $form['translatable']['#description'] = t('To configure translation for this field, <a href=":language-settings-url">enable language support</a> for this type.', array(
      ':language-settings-url' => $toggle_url,
    ));
  }
 
  if ($field->isTranslatable()) {
    module_load_include('inc', 'content_translation', 'content_translation.admin');
    $element = content_translation_field_sync_widget($field);
    if ($element) {
      $form['third_party_settings']['content_translation']['translation_sync'] = $element;
      $form['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10;
    }
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.