From 605ed74f83b89a61cd929cb75665b9c7e9b549e3 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Tue, 8 Oct 2013 13:15:53 +0100
Subject: [PATCH] Issue #2105407 by swentel, plach: Fixed Changing language
 settings for fields ends in a fatal error.

---
 .../content_translation.module                |  6 ++--
 .../Tests/ContentTranslationSyncImageTest.php | 35 ++++++++++++++++++-
 .../entity_test/Entity/EntityTestMul.php      |  3 +-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module
index c8bd7bb72640..20d72edaabc8 100644
--- a/core/modules/content_translation/content_translation.module
+++ b/core/modules/content_translation/content_translation.module
@@ -810,9 +810,9 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, a
  * Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_edit_form'.
  */
 function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state, $form_id) {
-  if ($form['#instance']->isFieldTranslatable()) {
+  if ($form['#field']->isFieldTranslatable()) {
     module_load_include('inc', 'content_translation', 'content_translation.admin');
-    $element = content_translation_field_sync_widget($form['#instance']);
+    $element = content_translation_field_sync_widget($form['#field']);
     if ($element) {
       $form['instance']['settings']['translation_sync'] = $element;
     }
@@ -997,7 +997,7 @@ function content_translation_save_settings($settings) {
             // If the field does not have translatable enabled we need to reset
             // the sync settings to their defaults.
             else {
-              unset($instance['settings']['translation_sync']);
+              unset($instance->settings['translation_sync']);
             }
             $instance->save();
           }
diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php
index c813790374d9..9789dc5f2b7d 100644
--- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php
+++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php
@@ -34,7 +34,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
    *
    * @var array
    */
-  public static $modules = array('language', 'content_translation', 'entity_test', 'image');
+  public static $modules = array('language', 'content_translation', 'entity_test', 'image', 'field_ui');
 
   public static function getInfo() {
     return array(
@@ -79,10 +79,43 @@ protected function setupTestFields() {
     ))->save();
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditorPermissions() {
+    // Every entity-type-specific test needs to define these.
+    return array('administer entity_test_mul fields', 'administer languages', 'administer content translation');
+  }
+
   /**
    * Tests image field field synchronization.
    */
   function testImageFieldSync() {
+    // Check that the alt and title fields are enabled for the image field.
+    $this->drupalLogin($this->editor);
+    $this->drupalGet('entity_test_mul/structure/' . $this->entityType . '/fields/' . $this->entityType . '.' . $this->entityType . '.' . $this->fieldName);
+    $this->assertFieldChecked('edit-instance-settings-translation-sync-alt');
+    $this->assertFieldChecked('edit-instance-settings-translation-sync-title');
+    $edit = array(
+      'instance[settings][translation_sync][alt]' => FALSE,
+      'instance[settings][translation_sync][title]' => FALSE,
+    );
+    $this->drupalPostForm(NULL, $edit, t('Save settings'));
+
+    // Check that the content translation settings page reflects the changes
+    // performed in the field edit page.
+    $this->drupalGet('admin/config/regional/content-language');
+    $this->assertNoFieldChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-alt');
+    $this->assertNoFieldChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-title');
+    $edit = array(
+      'settings[entity_test_mul][entity_test_mul][columns][field_test_et_ui_image][alt]' => TRUE,
+      'settings[entity_test_mul][entity_test_mul][columns][field_test_et_ui_image][title]' => TRUE,
+    );
+    $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save'));
+    $this->assertFieldChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-alt');
+    $this->assertFieldChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-title');
+    $this->drupalLogin($this->translator);
+
     $default_langcode = $this->langcodes[0];
     $langcode = $this->langcodes[1];
 
diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php
index 2081873a8c2b..81c251d2ce5f 100644
--- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php
+++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php
@@ -35,7 +35,8 @@
  *     "uuid" = "uuid",
  *     "bundle" = "type"
  *   },
- *   menu_base_path = "entity_test_mul/manage/%entity_test_mul"
+ *   menu_base_path = "entity_test_mul/manage/%entity_test_mul",
+ *   route_base_path = "entity_test_mul/structure/{bundle}"
  * )
  */
 class EntityTestMul extends EntityTest {
-- 
GitLab