getDefinition($field->getType()); $column_groups = $definition['column_groups']; if (!empty($column_groups) && count($column_groups) > 1) { $options = array(); $default = array(); foreach ($column_groups as $group => $info) { $options[$group] = $info['label']; $default[$group] = !empty($info['translatable']) ? $group : FALSE; } $settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file'))); $translation_sync = $field->getSetting('translation_sync'); $element = array( '#type' => 'checkboxes', '#title' => t('Translatable elements'), '#options' => $options, '#default_value' => !empty($translation_sync) ? $translation_sync : $default, '#attached' => array( 'library' => array( 'content_translation/drupal.content_translation.admin', ), 'js' => array( array('data' => array('contentTranslationDependentOptions' => $settings), 'type' => 'setting'), ), ), ); } return $element; } /** * (proxied) Implements hook_form_FORM_ID_alter(). */ function _content_translation_form_language_content_settings_form_alter(array &$form, FormStateInterface $form_state) { // Inject into the content language settings the translation settings if the // user has the required permission. if (!\Drupal::currentUser()->hasPermission('administer content translation')) { return; } $default = $form['entity_types']['#default_value']; foreach ($default as $entity_type_id => $enabled) { $default[$entity_type_id] = $enabled || content_translation_enabled($entity_type_id) ? $entity_type_id : FALSE; } $form['entity_types']['#default_value'] = $default; $form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin'; $form['#attached']['js'][] = array('data' => drupal_get_path('module', 'content_translation') . '/content_translation.admin.js', 'type' => 'file'); $dependent_options_settings = array(); $entity_manager = Drupal::entityManager(); foreach ($form['#labels'] as $entity_type_id => $label) { $entity_type = $entity_manager->getDefinition($entity_type_id); $storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array(); foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) { // Here we do not want the widget to be altered and hold also the "Enable // translation" checkbox, which would be redundant. Hence we add this key // to be able to skip alterations. $form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE; // Only show the checkbox to enable translation if the bundles in the // entity might have fields and if there are fields to translate. if ($entity_type->isFieldable()) { $fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle); if ($fields) { $form['settings'][$entity_type_id][$bundle]['translatable'] = array( '#type' => 'checkbox', '#default_value' => content_translation_enabled($entity_type_id, $bundle), ); $field_settings = content_translation_get_config($entity_type_id, $bundle, 'fields'); foreach ($fields as $field_name => $definition) { // Allow to configure only fields supporting multilingual storage. if (!empty($storage_definitions[$field_name]) && $storage_definitions[$field_name]->isTranslatable()) { $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array( '#label' => $definition->getLabel(), '#type' => 'checkbox', '#default_value' => $definition->isTranslatable(), ); // Display the column translatability configuration widget. // @todo Remove this special casing when arbitrary settings can be // stored for any field. See https://drupal.org/node/2224761. if ($definition instanceof FieldInstanceConfigInterface) { $column_element = content_translation_field_sync_widget($definition); if ($column_element) { $form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element; // @todo This should not concern only files. if (isset($column_element['#options']['file'])) { $dependent_options_settings["settings[{$entity_type_id}][{$bundle}][columns][{$field_name}]"] = array('file'); } } } } } } } } } $settings = array('dependent_selectors' => $dependent_options_settings); $form['#attached']['js'][] = array('data' => array('contentTranslationDependentOptions' => $settings), 'type' => 'setting'); $form['#validate'][] = 'content_translation_form_language_content_settings_validate'; $form['#submit'][] = 'content_translation_form_language_content_settings_submit'; } /** * (proxied) Implements hook_preprocess_HOOK(); */ function _content_translation_preprocess_language_content_settings_table(&$variables) { // Alter the 'build' variable injecting the translation settings if the user // has the required permission. if (!\Drupal::currentUser()->hasPermission('administer content translation')) { return; } $element = $variables['element']; $build = &$variables['build']; array_unshift($build['#header'], array('data' => t('Translatable'), 'class' => array('translatable'))); $rows = array(); foreach (Element::children($element) as $bundle) { $field_names = !empty($element[$bundle]['fields']) ? Element::children($element[$bundle]['fields']) : array(); if (!empty($element[$bundle]['translatable'])) { $checkbox_id = $element[$bundle]['translatable']['#id']; } $rows[$bundle] = $build['#rows'][$bundle]; if (!empty($element[$bundle]['translatable'])) { $translatable = array( 'data' => $element[$bundle]['translatable'], 'class' => array('translatable'), ); array_unshift($rows[$bundle]['data'], $translatable); $rows[$bundle]['data'][1]['data']['#prefix'] = '