function content_translation_form_language_content_settings_submit

Same name in other branches
  1. 9 core/modules/content_translation/content_translation.admin.inc \content_translation_form_language_content_settings_submit()
  2. 10 core/modules/content_translation/content_translation.admin.inc \content_translation_form_language_content_settings_submit()
  3. 11.x core/modules/content_translation/content_translation.admin.inc \content_translation_form_language_content_settings_submit()

Form submission handler for content_translation_admin_settings_form().

See also

content_translation_admin_settings_form_validate()

1 string reference to 'content_translation_form_language_content_settings_submit'
_content_translation_form_language_content_settings_form_alter in core/modules/content_translation/content_translation.admin.inc
(proxied) Implements hook_form_FORM_ID_alter().

File

core/modules/content_translation/content_translation.admin.inc, line 345

Code

function content_translation_form_language_content_settings_submit(array $form, FormStateInterface $form_state) {
    
    /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
    $content_translation_manager = \Drupal::service('content_translation.manager');
    $entity_types = $form_state->getValue('entity_types');
    $settings =& $form_state->getValue('settings');
    // If an entity type is not translatable all its bundles and fields must be
    // marked as non-translatable. Similarly, if a bundle is made non-translatable
    // all of its fields will be not translatable.
    foreach ($settings as $entity_type_id => &$entity_settings) {
        foreach ($entity_settings as $bundle => &$bundle_settings) {
            $fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
            if (!empty($bundle_settings['translatable'])) {
                $bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type_id];
            }
            if (!empty($bundle_settings['fields'])) {
                foreach ($bundle_settings['fields'] as $field_name => $translatable) {
                    $translatable = $translatable && $bundle_settings['translatable'];
                    // If we have column settings and no column is translatable, no point
                    // in making the field translatable.
                    if (isset($bundle_settings['columns'][$field_name]) && !array_filter($bundle_settings['columns'][$field_name])) {
                        $translatable = FALSE;
                    }
                    $field_config = $fields[$field_name]->getConfig($bundle);
                    if ($field_config->isTranslatable() != $translatable) {
                        $field_config->setTranslatable($translatable)
                            ->save();
                    }
                }
            }
            if (isset($bundle_settings['translatable'])) {
                // Store whether a bundle has translation enabled or not.
                $content_translation_manager->setEnabled($entity_type_id, $bundle, $bundle_settings['translatable']);
                // Store any other bundle settings.
                if ($content_translation_manager instanceof BundleTranslationSettingsInterface) {
                    $content_translation_manager->setBundleTranslationSettings($entity_type_id, $bundle, $bundle_settings['settings']['content_translation']);
                }
                // Save translation_sync settings.
                if (!empty($bundle_settings['columns'])) {
                    foreach ($bundle_settings['columns'] as $field_name => $column_settings) {
                        $field_config = $fields[$field_name]->getConfig($bundle);
                        if ($field_config->isTranslatable()) {
                            $field_config->setThirdPartySetting('content_translation', 'translation_sync', $column_settings);
                        }
                        else {
                            $field_config->unsetThirdPartySetting('content_translation', 'translation_sync');
                        }
                        $field_config->save();
                    }
                }
            }
        }
    }
    // Ensure entity and menu router information are correctly rebuilt.
    \Drupal::entityTypeManager()->clearCachedDefinitions();
    \Drupal::service('router.builder')->setRebuildNeeded();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.