content_translation_form_language_content_settings_submit

content_translation_form_language_content_settings_submit(array $form, FormStateInterface $form_state)

Form submission handler for content_translation_admin_settings_form().

See also

content_translation_admin_settings_form_validate()

File

core/modules/content_translation/content_translation.admin.inc, line 319
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);
            }
            // If the field does not have translatable enabled we need to reset
            // the sync settings to their defaults.
            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();

}
doc_Drupal
2016-10-29 08:58:38
Comments
Leave a Comment

Please login to continue.