Commit ae0984f8 authored by catch's avatar catch

Issue #1942346 by swentel: Convert Field API variables to CMI.

parent 2d6ed6c8
......@@ -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'));
}
/**
......
......@@ -24,6 +24,11 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->installConfig(array('field'));
}
/**
* Tests basic CRUD operations on EntityDisplay objects.
*/
......
default_storage: field_sql_storage
language_fallback: '1'
purge_batch_size: 10
......@@ -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'
......@@ -1140,7 +1140,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']);
}
}
......
......@@ -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.
......
......@@ -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().
*
......
......@@ -470,6 +470,19 @@ function field_update_8003() {
$state->set('field.instance.deleted', $deleted_instances);
}
/**
* 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.
......
......@@ -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
......
......@@ -63,41 +63,6 @@
* the Field API.
*/
/**
* 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.
*
......@@ -185,6 +150,13 @@ function field_content_languages() {
return array_keys(language_list(LANGUAGE_ALL));
}
/**
* 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.
*
......@@ -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);
......
......@@ -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.
......
......@@ -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());
}
......
......@@ -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 {
......
......@@ -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.
......
......@@ -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'));
}
/**
......
......@@ -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(
......
......@@ -63,6 +63,8 @@ protected function setUp() {
$this->entity->save();
$this->serializer = $this->container->get('serializer');
$this->installConfig(array('field'));
}
/**
......
......@@ -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(
......
......@@ -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'));
}
/**
......
......@@ -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.
......
......@@ -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';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment