diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index bdf56c5..d3737bb 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -13,7 +13,6 @@ * Parent class for Edit tests. */ class EditTestBase extends DrupalUnitTestBase { - var $default_storage = 'field_sql_storage'; /** * Modules to enable. @@ -29,9 +28,7 @@ function setUp() { $this->installSchema('system', 'variable'); $this->installSchema('entity_test', array('entity_test', 'entity_test_rev')); - - // Set default storage backend. - variable_set('field_storage_default', $this->default_storage); + $this->installConfig(array('field')); } /** diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 1257f48..11f6da7 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -24,6 +24,11 @@ public static function getInfo() { ); } + protected function setUp() { + parent::setUp(); + $this->installConfig(array('field')); + } + /** * Tests basic CRUD operations on EntityDisplay objects. */ diff --git a/core/modules/field/config/field.settings.yml b/core/modules/field/config/field.settings.yml index b6172c1..5ca0000 100644 --- a/core/modules/field/config/field.settings.yml +++ b/core/modules/field/config/field.settings.yml @@ -1 +1,3 @@ +default_storage: field_sql_storage +language_fallback: '1' purge_batch_size: 10 diff --git a/core/modules/field/config/schema/field.schema.yml b/core/modules/field/config/schema/field.schema.yml index b9e51d6..238409e 100644 --- a/core/modules/field/config/schema/field.schema.yml +++ b/core/modules/field/config/schema/field.schema.yml @@ -4,6 +4,12 @@ field.settings: type: mapping label: 'Field settings' mapping: + default_storage: + type: string + label: 'The default storage backend for a field' + language_fallback: + type: boolean + label: 'Whether the field display falls back to global language fallback configuration' purge_batch_size: type: integer label: 'Maximum number of field data records to purge' diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 7b95762..850912e 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -1142,7 +1142,7 @@ function hook_field_attach_prepare_translation_alter(\Drupal\Core\Entity\EntityI function hook_field_language_alter(&$display_langcode, $context) { // Do not apply core language fallback rules if they are disabled or if Locale // is not registered as a translation handler. - if (variable_get('field_language_fallback', TRUE) && field_has_translation_handler($context['entity']->entityType())) { + if (field_language_fallback_enabled() && field_has_translation_handler($context['entity']->entityType())) { field_language_fallback($display_langcode, $context['entity'], $context['langcode']); } } diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 51d2d57..cde15f4 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -22,8 +22,9 @@ * the data in SQL differently or use a completely different storage mechanism * such as a cloud-based database. * - * Each field defines which storage backend it uses. The Drupal system variable - * 'field_storage_default' identifies the storage backend used by default. + * Each field defines which storage backend it uses. The Drupal configuration + * 'field.settings.default_storage' identifies the storage backend used by + * default. * * See @link field Field API @endlink for information about the other parts of * the Field API. diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index 14566f2..9880824 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -45,8 +45,8 @@ * - settings: each omitted setting is given the default value defined in * hook_field_info(). * - storage: - * - type: the storage backend specified in the 'field_storage_default' - * system variable. + * - type: the storage backend specified in the + * 'field.settings.default_storage' configuration. * - settings: each omitted setting is given the default value specified in * hook_field_storage_info(). * diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 663ae69..b103222 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -481,6 +481,19 @@ function field_update_8003() { } /** + * Moves field_storage_default and field_language_fallback to config. + * + * @ingroup config_upgrade + */ +function field_update_8004() { + update_variable_set('field_language_fallback', TRUE); + update_variables_to_config('field.settings', array( + 'field_storage_default' => 'default_storage', + 'field_language_fallback' => 'language_fallback', + )); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 1e31484..8f459a3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -333,7 +333,7 @@ function field_field_widget_info_alter(&$info) { * otherwise all the fallback candidates are inspected to see if there is a * field translation available in another language. * By default this is called by field_field_language_alter(), but this - * behavior can be disabled by setting the 'field_language_fallback' + * behavior can be disabled by setting the 'field.settings.language_fallback' * variable to FALSE. * * @param $field_langcodes diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index 8e5ee39..55b364e 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -64,41 +64,6 @@ */ /** - * Implements hook_language_insert(). - */ -function field_language_insert() { - field_info_cache_clear(); - // If the number of languages is bigger than 1, enable the core language - // fallback rules. - // Because the language_count is updated only after the hook is invoked, we - // check if the language_count is bigger or equal with 1 at the current time. - if (variable_get('language_count', 1) >= 1) { - variable_set('field_language_fallback', TRUE); - } -} - -/** - * Implements hook_language_update(). - */ -function field_language_update() { - field_info_cache_clear(); -} - -/** - * Implements hook_language_delete(). - */ -function field_language_delete() { - field_info_cache_clear(); - // If the number of languages is less than 2, disable the core language - // fallback rules. - // Because the language_count is updated after the hook is invoked, we check - // if the language_count is less or equal with 2 at the current time. - if (variable_get('language_count', 1) <= 2) { - variable_set('field_language_fallback', FALSE); - } -} - -/** * Collects the available language codes for the given entity type and field. * * If the given field has language support enabled, an array of available @@ -186,6 +151,13 @@ function field_content_languages() { } /** + * Checks whether field language fallback is enabled. + */ +function field_language_fallback_enabled() { + return language_multilingual() && config('field.settings')->get('language_fallback'); +} + +/** * Checks whether a field has language support. * * A field has language support enabled if its 'translatable' property is set to @@ -317,7 +289,7 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = ); // Do not apply core language fallback rules if they are disabled or if // the entity does not have a translation handler registered. - if (variable_get('field_language_fallback', FALSE) && field_has_translation_handler($entity_type)) { + if (field_language_fallback_enabled() && field_has_translation_handler($entity_type)) { field_language_fallback($display_langcode, $context['entity'], $context['langcode']); } drupal_alter('field_language', $display_langcode, $context); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php index 14d02e8..b899533 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -323,7 +323,7 @@ public function save() { // Provide default storage. $this->storage += array( - 'type' => variable_get('field_storage_default', 'field_sql_storage'), + 'type' => config('field.settings')->get('default_storage'), 'settings' => array(), ); // Check that the storage type is known. diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index c288750..2e91a31 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -193,7 +193,7 @@ public function query($use_groupby = FALSE) { $this->view->display_handler->options['field_langcode']); $placeholder = $this->placeholder(); $langcode_fallback_candidates = array($langcode); - if (variable_get('locale_field_language_fallback', TRUE)) { + if (field_language_fallback_enabled()) { require_once DRUPAL_ROOT . '/includes/language.inc'; $langcode_fallback_candidates = array_merge($langcode_fallback_candidates, language_fallback_get_candidates()); } diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index a0afa3f..9ee6019 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -63,7 +63,7 @@ function testCreateField() { $this->assertEqual($field_config['settings'], $field_type['settings'], 'Default field settings have been written.'); // Ensure that default storage was set. - $this->assertEqual($field_config['storage']['type'], variable_get('field_storage_default'), 'The field type is properly saved.'); + $this->assertEqual($field_config['storage']['type'], config('field.settings')->get('default_storage'), 'The field type is properly saved.'); // Guarantee that the name is unique. try { diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldTestBase.php index a34586e..3944639 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldTestBase.php @@ -14,17 +14,6 @@ * Parent class for Field API tests. */ abstract class FieldTestBase extends WebTestBase { - var $default_storage = 'field_sql_storage'; - - /** - * Set the default field storage backend for fields created during tests. - */ - function setUp() { - parent::setUp(); - - // Set default storage backend. - variable_set('field_storage_default', $this->default_storage); - } /** * Generate random values for a field_test field. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index 3e1bf38..223e0ac 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -14,7 +14,6 @@ * Parent class for Field API unit tests. */ abstract class FieldUnitTestBase extends DrupalUnitTestBase { - var $default_storage = 'field_sql_storage'; /** * Modules to enable. @@ -40,7 +39,7 @@ function setUp() { $this->installSchema('field_test', array('test_entity', 'test_entity_revision', 'test_entity_bundle')); // Set default storage backend. - variable_set('field_storage_default', $this->default_storage); + $this->installConfig(array('field')); } /** diff --git a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php index 8391d0e..b40bffa 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php @@ -62,6 +62,7 @@ function setUp() { $this->installSchema('user', array('users')); $this->installSchema('language', array('language')); $this->installSchema('entity_test', array('entity_test')); + $this->installConfig(array('field')); // Add English as a language. $english = new Language(array( diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php index 5afc882..f6c106e 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php @@ -63,6 +63,8 @@ protected function setUp() { $this->entity->save(); $this->serializer = $this->container->get('serializer'); + + $this->installConfig(array('field')); } /** diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php index d485a5b..1d9bff6 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.php @@ -23,6 +23,7 @@ protected function setUp() { $this->installSchema('entity_test', array('entity_test_mulrev', 'entity_test_mulrev_property_revision', 'entity_test_mulrev_property_data')); $this->installSchema('system', array('url_alias')); + $this->installConfig(array('field')); // Auto-create a field for testing. field_create_field(array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php index c3f236b..41918d3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php @@ -26,6 +26,7 @@ public function setUp() { $this->installSchema('user', 'users'); $this->installSchema('system', 'sequences'); $this->installSchema('entity_test', 'entity_test'); + $this->installConfig(array('field')); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php index 5e08eed..a460b6f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php @@ -41,6 +41,8 @@ public static function getInfo() { protected function setUp() { parent::setUp(); + // Install field configuration. + $this->installConfig(array('field')); // The users table is needed for creating dummy user accounts. $this->installSchema('user', array('users')); // Register entity_test text field. diff --git a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php index 2000ffd..7126384 100644 --- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php @@ -45,6 +45,8 @@ public static function getInfo() { function setUp() { parent::setUp(); + $this->installConfig(array('field')); + // @todo Add helper methods for all of the following. $this->entity_type = 'test_entity';