You are here

function content_translation_form_language_content_settings_submit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 315
The content translation administration forms.

Code

function content_translation_form_language_content_settings_submit(array $form, FormStateInterface $form_state) {
  $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::entityManager()
        ->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.
        \Drupal::service('content_translation.manager')
          ->setEnabled($entity_type_id, $bundle, $bundle_settings['translatable']);

        // 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::entityManager()
    ->clearCachedDefinitions();
  \Drupal::service('router.builder')
    ->setRebuildNeeded();
}