Issue #2174509 by amateescu, chx: Drupal\Core\Field\FieldDefinition::getSchema() is broken.

8.0.x
Alex Pott 2014-01-25 17:04:02 +01:00
parent 1b252e2932
commit fde84e2a5f
2 changed files with 24 additions and 1 deletions

View File

@ -24,6 +24,11 @@ class FieldDefinition extends ListDefinition implements FieldDefinitionInterface
*/
protected $schema;
/**
* @var array
*/
protected $indexes = array();
/**
* Creates a new field definition.
*
@ -286,7 +291,7 @@ class FieldDefinition extends ListDefinition implements FieldDefinitionInterface
public function getSchema() {
if (!isset($this->schema)) {
// Get the schema from the field item class.
$definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getFieldType());
$definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType());
$class = $definition['class'];
$schema = $class::schema($this);
// Fill in default values for optional entries.

View File

@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
@ -83,6 +84,23 @@ class TestItemTest extends FieldUnitTestBase {
$entity->save();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->{$this->field_name}->value, $new_value);
// Test the schema for this field type.
$expected_schema = array(
'columns' => array(
'value' => array(
'type' => 'int',
'size' => 'medium',
'not null' => FALSE,
),
),
'indexes' => array(
'value' => array('value'),
),
'foreign keys' => array(),
);
$field_schema = FieldDefinition::create('test_field')->getSchema();
$this->assertEqual($field_schema, $expected_schema);
}
}