Skip to content
Snippets Groups Projects
Commit fde84e2a authored by Alex Pott's avatar Alex Pott
Browse files

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

parent 1b252e29
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment