Issue #2174509 by amateescu, chx: Drupal\Core\Field\FieldDefinition::getSchema() is broken.
parent
1b252e2932
commit
fde84e2a5f
|
@ -24,6 +24,11 @@ class FieldDefinition extends ListDefinition implements FieldDefinitionInterface
|
||||||
*/
|
*/
|
||||||
protected $schema;
|
protected $schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $indexes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new field definition.
|
* Creates a new field definition.
|
||||||
*
|
*
|
||||||
|
@ -286,7 +291,7 @@ class FieldDefinition extends ListDefinition implements FieldDefinitionInterface
|
||||||
public function getSchema() {
|
public function getSchema() {
|
||||||
if (!isset($this->schema)) {
|
if (!isset($this->schema)) {
|
||||||
// Get the schema from the field item class.
|
// 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'];
|
$class = $definition['class'];
|
||||||
$schema = $class::schema($this);
|
$schema = $class::schema($this);
|
||||||
// Fill in default values for optional entries.
|
// Fill in default values for optional entries.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\field\Tests;
|
namespace Drupal\field\Tests;
|
||||||
|
|
||||||
|
use Drupal\Core\Field\FieldDefinition;
|
||||||
use Drupal\Core\Field\FieldItemInterface;
|
use Drupal\Core\Field\FieldItemInterface;
|
||||||
use Drupal\Core\Field\FieldItemListInterface;
|
use Drupal\Core\Field\FieldItemListInterface;
|
||||||
|
|
||||||
|
@ -83,6 +84,23 @@ class TestItemTest extends FieldUnitTestBase {
|
||||||
$entity->save();
|
$entity->save();
|
||||||
$entity = entity_load('entity_test', $id);
|
$entity = entity_load('entity_test', $id);
|
||||||
$this->assertEqual($entity->{$this->field_name}->value, $new_value);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue