Commit 288f240c authored by catch's avatar catch
Browse files

Issue #1957204 by yched: Stop exposing dynamic field data tables in hook_schema()

parent 2d329312
...@@ -7,32 +7,6 @@ ...@@ -7,32 +7,6 @@
use Drupal\field\Plugin\Core\Entity\Field; use Drupal\field\Plugin\Core\Entity\Field;
/**
* Implements hook_schema().
*/
function field_sql_storage_schema() {
$schema = array();
// Loading entities within hook_schema() triggers lots of race conditions.
// Read definitions for raw storage instead (configuration, and state for
// deleted fields).
$fields = array();
foreach (config_get_storage_names_with_prefix('field.field') as $name) {
$fields[] = config($name)->get();
}
$deleted_fields = Drupal::state()->get('field.field.deleted') ?: array();
$fields = array_merge($fields, $deleted_fields);
foreach ($fields as $field) {
if ($field['storage']['type'] == 'field_sql_storage') {
$field = new Field($field);
$schema += _field_sql_storage_schema($field);
}
}
return $schema;
}
/** /**
* Writes field data directly to SQL storage. * Writes field data directly to SQL storage.
* *
......
...@@ -449,7 +449,8 @@ function testFieldSqlStorageForeignKeys() { ...@@ -449,7 +449,8 @@ function testFieldSqlStorageForeignKeys() {
$this->assertEqual($field['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', t('Foreign key column name modified after update')); $this->assertEqual($field['foreign keys'][$foreign_key_name]['columns'][$foreign_key_name], 'id', t('Foreign key column name modified after update'));
// Now grab the SQL schema and verify that too. // Now grab the SQL schema and verify that too.
$schema = drupal_get_schema(_field_sql_storage_tablename($field), TRUE); $schemas = _field_sql_storage_schema($field);
$schema = $schemas[_field_sql_storage_tablename($field)];
$this->assertEqual(count($schema['foreign keys']), 1, 'There is 1 foreign key in the schema'); $this->assertEqual(count($schema['foreign keys']), 1, 'There is 1 foreign key in the schema');
$foreign_key = reset($schema['foreign keys']); $foreign_key = reset($schema['foreign keys']);
$foreign_key_column = _field_sql_storage_columnname($field['field_name'], $foreign_key_name); $foreign_key_column = _field_sql_storage_columnname($field['field_name'], $foreign_key_name);
......
...@@ -146,11 +146,7 @@ function testImageFieldSettings() { ...@@ -146,11 +146,7 @@ function testImageFieldSettings() {
$widget_settings = array( $widget_settings = array(
'preview_image_style' => 'medium', 'preview_image_style' => 'medium',
); );
$field = $this->createImageField($field_name, 'article', array(), $instance_settings, $widget_settings); $instance = $this->createImageField($field_name, 'article', array(), $instance_settings, $widget_settings);
$field['deleted'] = 0;
$table = _field_sql_storage_tablename($field);
$schema = drupal_get_schema($table, TRUE);
$instance = field_info_instance('node', $field_name, 'article');
$this->drupalGet('node/add/article'); $this->drupalGet('node/add/article');
$this->assertText(t('Files must be less than 50 KB.'), 'Image widget max file size is displayed on article form.'); $this->assertText(t('Files must be less than 50 KB.'), 'Image widget max file size is displayed on article form.');
...@@ -198,12 +194,13 @@ function testImageFieldSettings() { ...@@ -198,12 +194,13 @@ function testImageFieldSettings() {
$field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]' => $this->randomName($test_size), $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]' => $this->randomName($test_size),
); );
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published'));
$schema = $instance->getField()->getSchema();
$this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array( $this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array(
'%max' => $schema['fields'][$field_name .'_alt']['length'], '%max' => $schema['columns']['alt']['length'],
'%length' => $test_size, '%length' => $test_size,
))); )));
$this->assertRaw(t('Title cannot be longer than %max characters but is currently %length characters long.', array( $this->assertRaw(t('Title cannot be longer than %max characters but is currently %length characters long.', array(
'%max' => $schema['fields'][$field_name .'_title']['length'], '%max' => $schema['columns']['title']['length'],
'%length' => $test_size, '%length' => $test_size,
))); )));
} }
......
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