Commit fde84e2a authored by alexpott's avatar alexpott

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

parent 1b252e29
......@@ -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 @@ public function getDefaultValue(EntityInterface $entity) {
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.
......
......@@ -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 @@ public function testTestItem() {
$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);
}
}
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