Commit 9e354fa9 authored by Dries's avatar Dries

Issue #1965208 by amateescu, Berdir: Convert TaxonomyTermReferenceItem to...

Issue #1965208 by amateescu, Berdir: Convert TaxonomyTermReferenceItem to extend EntityReferenceItem.
parent 31fe58d1
...@@ -277,11 +277,11 @@ function forum_node_validate(EntityInterface $node, $form) { ...@@ -277,11 +277,11 @@ function forum_node_validate(EntityInterface $node, $form) {
foreach ($node->taxonomy_forums[$langcode] as $delta => $item) { foreach ($node->taxonomy_forums[$langcode] as $delta => $item) {
// If no term was selected (e.g. when no terms exist yet), remove the // If no term was selected (e.g. when no terms exist yet), remove the
// item. // item.
if (empty($item['tid'])) { if (empty($item['target_id'])) {
unset($node->taxonomy_forums[$langcode][$delta]); unset($node->taxonomy_forums[$langcode][$delta]);
continue; continue;
} }
$term = taxonomy_term_load($item['tid']); $term = taxonomy_term_load($item['target_id']);
if (!$term) { if (!$term) {
form_set_error('taxonomy_forums', t('Select a forum.')); form_set_error('taxonomy_forums', t('Select a forum.'));
continue; continue;
...@@ -310,13 +310,13 @@ function forum_node_presave(EntityInterface $node) { ...@@ -310,13 +310,13 @@ function forum_node_presave(EntityInterface $node) {
reset($node->taxonomy_forums); reset($node->taxonomy_forums);
$langcode = key($node->taxonomy_forums); $langcode = key($node->taxonomy_forums);
if (!empty($node->taxonomy_forums[$langcode])) { if (!empty($node->taxonomy_forums[$langcode])) {
$node->forum_tid = $node->taxonomy_forums[$langcode][0]['tid']; $node->forum_tid = $node->taxonomy_forums[$langcode][0]['target_id'];
// Only do a shadow copy check if this is not a new node. // Only do a shadow copy check if this is not a new node.
if (!$node->isNew()) { if (!$node->isNew()) {
$old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField();
if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) {
// A shadow copy needs to be created. Retain new term and add old term. // A shadow copy needs to be created. Retain new term and add old term.
$node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); $node->taxonomy_forums[$langcode][] = array('target_id' => $old_tid);
} }
} }
} }
...@@ -515,7 +515,7 @@ function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields) ...@@ -515,7 +515,7 @@ function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields)
$query->values(array( $query->values(array(
'nid' => $entity->id(), 'nid' => $entity->id(),
'title' => $translation->title->value, 'title' => $translation->title->value,
'tid' => $translation->taxonomy_forums->tid, 'tid' => $translation->taxonomy_forums->target_id,
'sticky' => $entity->sticky, 'sticky' => $entity->sticky,
'created' => $entity->created, 'created' => $entity->created,
'comment_count' => 0, 'comment_count' => 0,
...@@ -550,7 +550,7 @@ function forum_field_storage_pre_update(EntityInterface $entity, &$skip_fields) ...@@ -550,7 +550,7 @@ function forum_field_storage_pre_update(EntityInterface $entity, &$skip_fields)
$query->values(array( $query->values(array(
'nid' => $entity->nid, 'nid' => $entity->nid,
'title' => $entity->title, 'title' => $entity->title,
'tid' => $item['tid'], 'tid' => $item['target_id'],
'sticky' => $entity->sticky, 'sticky' => $entity->sticky,
'created' => $entity->created, 'created' => $entity->created,
'comment_count' => 0, 'comment_count' => 0,
......
...@@ -529,7 +529,7 @@ function createForumTopic($forum, $container = FALSE) { ...@@ -529,7 +529,7 @@ function createForumTopic($forum, $container = FALSE) {
// Retrieve node object, ensure that the topic was created and in the proper forum. // Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this->drupalGetNodeByTitle($title); $node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title))); $this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title)));
$this->assertEqual($node->taxonomy_forums[Language::LANGCODE_NOT_SPECIFIED][0]['tid'], $tid, 'Saved forum topic was in the expected forum'); $this->assertEqual($node->taxonomy_forums[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], $tid, 'Saved forum topic was in the expected forum');
// View forum topic. // View forum topic.
$this->drupalGet('node/' . $node->nid); $this->drupalGet('node/' . $node->nid);
......
...@@ -87,7 +87,7 @@ public function testForumPager() { ...@@ -87,7 +87,7 @@ public function testForumPager() {
'nid' => NULL, 'nid' => NULL,
'type' => 'forum', 'type' => 'forum',
'taxonomy_forums' => array( 'taxonomy_forums' => array(
array('tid' => $tid) array('target_id' => $tid),
), ),
)); ));
} }
......
...@@ -110,7 +110,7 @@ public function setUp() { ...@@ -110,7 +110,7 @@ public function setUp() {
$entity->name->value = $this->randomName(); $entity->name->value = $this->randomName();
$index = $i ? 1 : 0; $index = $i ? 1 : 0;
$entity->user_id->target_id = $this->accounts[$index]->uid; $entity->user_id->target_id = $this->accounts[$index]->uid;
$entity->{$this->fieldName}->tid = $this->terms[$index]->id(); $entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
$entity->save(); $entity->save();
$this->entities[] = $entity; $this->entities[] = $entity;
} }
...@@ -152,7 +152,7 @@ public function testQuery() { ...@@ -152,7 +152,7 @@ public function testQuery() {
// This returns the 0th entity as that's only one pointing to the 0th // This returns the 0th entity as that's only one pointing to the 0th
// term (test with specifying the column name). // term (test with specifying the column name).
$this->queryResults = $this->factory->get('entity_test') $this->queryResults = $this->factory->get('entity_test')
->condition("$this->fieldName.tid.entity.name", $this->terms[0]->name->value) ->condition("$this->fieldName.target_id.entity.name", $this->terms[0]->name->value)
->execute(); ->execute();
$this->assertResults(array(0)); $this->assertResults(array(0));
// This returns the 1st and 2nd entity as those point to the 1st term. // This returns the 1st and 2nd entity as those point to the 1st term.
......
...@@ -102,7 +102,7 @@ function setUp() { ...@@ -102,7 +102,7 @@ function setUp() {
'title' => $this->xss_label, 'title' => $this->xss_label,
'type' => 'article', 'type' => 'article',
'promote' => NODE_PROMOTED, 'promote' => NODE_PROMOTED,
'field_tags' => array(array('tid' => $this->term->id())), 'field_tags' => array(array('target_id' => $this->term->id())),
)); ));
// Create a test comment on the test node. // Create a test comment on the test node.
......
...@@ -33,9 +33,10 @@ class LinkFormatter extends TaxonomyFormatterBase { ...@@ -33,9 +33,10 @@ class LinkFormatter extends TaxonomyFormatterBase {
public function viewElements(EntityInterface $entity, $langcode, array $items) { public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array(); $elements = array();
// Terms without tid do not exist yet, theme such terms as just their name. // Terms without target_id do not exist yet, theme such terms as just their
// name.
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
if (!$item['tid']) { if (!$item['target_id']) {
$elements[$delta] = array( $elements[$delta] = array(
'#markup' => check_plain($item['entity']->label()), '#markup' => check_plain($item['entity']->label()),
); );
......
...@@ -31,10 +31,10 @@ class RSSCategoryFormatter extends TaxonomyFormatterBase { ...@@ -31,10 +31,10 @@ class RSSCategoryFormatter extends TaxonomyFormatterBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function viewElements(EntityInterface $entity, $langcode, array $items) { public function viewElements(EntityInterface $entity, $langcode, array $items) {
// Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is // Terms whose target_id is 'autocreate' do not exist yet and
// not set. Theme such terms as just their name. // $item['entity'] is not set. Theme such terms as just their name.
foreach ($items as $item) { foreach ($items as $item) {
if ($item['tid']) { if ($item['target_id']) {
$value = $item['entity']->label(); $value = $item['entity']->label();
$uri = $item['entity']->uri(); $uri = $item['entity']->uri();
......
...@@ -30,8 +30,8 @@ public function prepareView(array $entities, $langcode, array &$items) { ...@@ -30,8 +30,8 @@ public function prepareView(array $entities, $langcode, array &$items) {
foreach ($entities as $id => $entity) { foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) { foreach ($items[$id] as $delta => $item) {
// Force the array key to prevent duplicates. // Force the array key to prevent duplicates.
if ($item['tid'] !== 0) { if ($item['target_id'] !== 0) {
$tids[$item['tid']] = $item['tid']; $tids[$item['target_id']] = $item['target_id'];
} }
} }
} }
...@@ -46,12 +46,12 @@ public function prepareView(array $entities, $langcode, array &$items) { ...@@ -46,12 +46,12 @@ public function prepareView(array $entities, $langcode, array &$items) {
foreach ($items[$id] as $delta => $item) { foreach ($items[$id] as $delta => $item) {
// Check whether the taxonomy term field instance value could be // Check whether the taxonomy term field instance value could be
// loaded. // loaded.
if (isset($terms[$item['tid']])) { if (isset($terms[$item['target_id']])) {
// Replace the instance value with the term data. // Replace the instance value with the term data.
$items[$id][$delta]['entity'] = $terms[$item['tid']]; $items[$id][$delta]['entity'] = $terms[$item['target_id']];
} }
// Terms to be created are not in $terms, but are still legitimate. // Terms to be created are not in $terms, but are still legitimate.
elseif ($item['tid'] === 0 && isset($item['entity'])) { elseif ($item['target_id'] === 0 && isset($item['entity'])) {
// Leave the item in place. // Leave the item in place.
} }
// Otherwise, unset the instance value, since the term does not exist. // Otherwise, unset the instance value, since the term does not exist.
......
...@@ -50,7 +50,7 @@ public function settingsForm(array $form, array &$form_state) { ...@@ -50,7 +50,7 @@ public function settingsForm(array $form, array &$form_state) {
public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
$tags = array(); $tags = array();
foreach ($items as $item) { foreach ($items as $item) {
$tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']); $tags[$item['target_id']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['target_id']);
} }
$element += array( $element += array(
'#type' => 'textfield', '#type' => 'textfield',
...@@ -86,7 +86,7 @@ public function massageFormValues(array $values, array $form, array &$form_state ...@@ -86,7 +86,7 @@ public function massageFormValues(array $values, array $form, array &$form_state
// otherwise, create a new term. // otherwise, create a new term.
if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) { if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) {
$term = array_pop($possibilities); $term = array_pop($possibilities);
$item = array('tid' => $term->id()); $item = array('target_id' => $term->id());
} }
else { else {
$vocabulary = reset($vocabularies); $vocabulary = reset($vocabularies);
...@@ -94,7 +94,7 @@ public function massageFormValues(array $values, array $form, array &$form_state ...@@ -94,7 +94,7 @@ public function massageFormValues(array $values, array $form, array &$form_state
'vid' => $vocabulary->id(), 'vid' => $vocabulary->id(),
'name' => $value, 'name' => $value,
)); ));
$item = array('tid' => 0, 'entity' => $term); $item = array('target_id' => 0, 'entity' => $term);
} }
$items[] = $item; $items[] = $item;
} }
......
...@@ -77,14 +77,14 @@ public function testTaxonomyTermReferenceItem() { ...@@ -77,14 +77,14 @@ public function testTaxonomyTermReferenceItem() {
$tid = $this->term->id(); $tid = $this->term->id();
// Just being able to create the entity like this verifies a lot of code. // Just being able to create the entity like this verifies a lot of code.
$entity = entity_create('entity_test', array()); $entity = entity_create('entity_test', array());
$entity->field_test_taxonomy->tid = $this->term->id(); $entity->field_test_taxonomy->target_id = $this->term->id();
$entity->name->value = $this->randomName(); $entity->name->value = $this->randomName();
$entity->save(); $entity->save();
$entity = entity_load('entity_test', $entity->id()); $entity = entity_load('entity_test', $entity->id());
$this->assertTrue($entity->field_test_taxonomy instanceof FieldInterface, 'Field implements interface.'); $this->assertTrue($entity->field_test_taxonomy instanceof FieldInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertTrue($entity->field_test_taxonomy[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy->tid, $this->term->id()); $this->assertEqual($entity->field_test_taxonomy->target_id, $this->term->id());
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $this->term->name->value); $this->assertEqual($entity->field_test_taxonomy->entity->name->value, $this->term->name->value);
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $tid); $this->assertEqual($entity->field_test_taxonomy->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy->entity->uuid(), $this->term->uuid()); $this->assertEqual($entity->field_test_taxonomy->entity->uuid(), $this->term->uuid());
...@@ -105,7 +105,7 @@ public function testTaxonomyTermReferenceItem() { ...@@ -105,7 +105,7 @@ public function testTaxonomyTermReferenceItem() {
)); ));
$term2->save(); $term2->save();
$entity->field_test_taxonomy->tid = $term2->id(); $entity->field_test_taxonomy->target_id = $term2->id();
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id()); $this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id());
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $term2->name->value); $this->assertEqual($entity->field_test_taxonomy->entity->name->value, $term2->name->value);
} }
......
...@@ -84,7 +84,7 @@ function testTaxonomyTermFieldValidation() { ...@@ -84,7 +84,7 @@ function testTaxonomyTermFieldValidation() {
$langcode = Language::LANGCODE_NOT_SPECIFIED; $langcode = Language::LANGCODE_NOT_SPECIFIED;
$entity = entity_create('entity_test', array()); $entity = entity_create('entity_test', array());
$term = $this->createTerm($this->vocabulary); $term = $this->createTerm($this->vocabulary);
$entity->{$this->field_name}->tid = $term->id(); $entity->{$this->field_name}->target_id = $term->id();
try { try {
field_attach_validate($entity); field_attach_validate($entity);
$this->pass('Correct term does not cause validation error.'); $this->pass('Correct term does not cause validation error.');
...@@ -95,7 +95,7 @@ function testTaxonomyTermFieldValidation() { ...@@ -95,7 +95,7 @@ function testTaxonomyTermFieldValidation() {
$entity = entity_create('entity_test', array()); $entity = entity_create('entity_test', array());
$bad_term = $this->createTerm($this->createVocabulary()); $bad_term = $this->createTerm($this->createVocabulary());
$entity->{$this->field_name}->tid = $bad_term->id(); $entity->{$this->field_name}->target_id = $bad_term->id();
try { try {
field_attach_validate($entity); field_attach_validate($entity);
$this->fail('Wrong term causes validation error.'); $this->fail('Wrong term causes validation error.');
......
...@@ -171,7 +171,7 @@ function testTaxonomyIndex() { ...@@ -171,7 +171,7 @@ function testTaxonomyIndex() {
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); $this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Update the article to change one term. // Update the article to change one term.
$node->{$this->field_name_1}[$langcode] = array(array('tid' => $term_1->id())); $node->{$this->field_name_1}[$langcode] = array(array('target_id' => $term_1->id()));
$node->save(); $node->save();
// Check that both terms are indexed. // Check that both terms are indexed.
...@@ -187,7 +187,7 @@ function testTaxonomyIndex() { ...@@ -187,7 +187,7 @@ function testTaxonomyIndex() {
$this->assertEqual(1, $index_count, 'Term 2 is indexed.'); $this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term. // Update the article to change another term.
$node->{$this->field_name_2}[$langcode] = array(array('tid' => $term_1->id())); $node->{$this->field_name_2}[$langcode] = array(array('target_id' => $term_1->id()));
$node->save(); $node->save();
// Check that only one term is indexed. // Check that only one term is indexed.
......
...@@ -55,8 +55,8 @@ function setUp() { ...@@ -55,8 +55,8 @@ function setUp() {
$node = array(); $node = array();
$node['type'] = 'article'; $node['type'] = 'article';
$node['field_views_testing_tags'][]['tid'] = $this->term1->id(); $node['field_views_testing_tags'][]['target_id'] = $this->term1->id();
$node['field_views_testing_tags'][]['tid'] = $this->term2->id(); $node['field_views_testing_tags'][]['target_id'] = $this->term2->id();
$this->nodes[] = $this->drupalCreateNode($node); $this->nodes[] = $this->drupalCreateNode($node);
$this->nodes[] = $this->drupalCreateNode($node); $this->nodes[] = $this->drupalCreateNode($node);
} }
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
namespace Drupal\taxonomy\Type; namespace Drupal\taxonomy\Type;
use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Entity\Field\Type\EntityReferenceItem;
use Drupal\Core\TypedData\TypedDataInterface;
/** /**
* Defines the 'taxonomy_term_reference' entity field item. * Defines the 'taxonomy_term_reference' entity field item.
*/ */
class TaxonomyTermReferenceItem extends FieldItemBase { class TaxonomyTermReferenceItem extends EntityReferenceItem {
/** /**
* Property definitions of the contained properties. * Property definitions of the contained properties.
...@@ -25,47 +24,11 @@ class TaxonomyTermReferenceItem extends FieldItemBase { ...@@ -25,47 +24,11 @@ class TaxonomyTermReferenceItem extends FieldItemBase {
static $propertyDefinitions; static $propertyDefinitions;
/** /**
* Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). * {@inheritdoc}
*/ */
public function getPropertyDefinitions() { public function getPropertyDefinitions() {
if (!isset(static::$propertyDefinitions)) { $this->definition['settings']['target_type'] = 'taxonomy_term';
static::$propertyDefinitions['tid'] = array( return parent::getPropertyDefinitions();
'type' => 'integer',
'label' => t('Referenced taxonomy term id.'),
);
static::$propertyDefinitions['entity'] = array(
'type' => 'entity',
'constraints' => array(
'EntityType' => 'taxonomy_term',
),
'label' => t('Term'),
'description' => t('The referenced taxonomy term'),
// The entity object is computed out of the tid.
'computed' => TRUE,
'read-only' => FALSE,
'settings' => array('id source' => 'tid'),
);
}
return static::$propertyDefinitions;
} }
/**
* Overrides \Drupal\Core\Entity\Field\FieldItemBase::get().
*/
public function setValue($values, $notify = TRUE) {
// Treat the values as value of the entity property, if no array is
// given as this handles entity IDs and objects.
if (isset($values) && !is_array($values)) {
// Directly update the property instead of invoking the parent, so that
// the entity property can take care of updating the ID property.
$this->properties['entity']->setValue($values, $notify);
}
else {
// Make sure that the 'entity' property gets set as 'target_id'.
if (isset($values['tid']) && !isset($values['entity'])) {
$values['entity'] = $values['tid'];
}
parent::setValue($values, $notify);
}
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\Component\Uuid\Uuid; use Drupal\Component\Uuid\Uuid;
use Drupal\field\Plugin\Core\Entity\Field;
/** /**
* Implements hook_uninstall(). * Implements hook_uninstall().
...@@ -175,24 +176,36 @@ function taxonomy_schema() { ...@@ -175,24 +176,36 @@ function taxonomy_schema() {
function taxonomy_field_schema($field) { function taxonomy_field_schema($field) {
return array( return array(
'columns' => array( 'columns' => array(
'tid' => array( 'target_id' => array(
'type' => 'int', 'type' => 'int',
'unsigned' => TRUE, 'unsigned' => TRUE,
'not null' => FALSE, 'not null' => FALSE,
), ),
), ),
'indexes' => array( 'indexes' => array(
'tid' => array('tid'), 'target_id' => array('target_id'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'tid' => array( 'target_id' => array(
'table' => 'taxonomy_term_data', 'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'), 'columns' => array('target_id' => 'tid'),
), ),
), ),
); );
} }
/**
* Implements hook_update_dependencies().
*/
function taxonomy_update_dependencies() {
// Convert the 'tid' column of the taxonomy reference field to 'target_id'
// after fields and instances have been moved to the config system.
$dependencies['taxonomy'][8007] = array(
'field' => 8003,
);
return $dependencies;
}
/** /**
* Remove the {taxonomy_vocabulary}.module field. * Remove the {taxonomy_vocabulary}.module field.
*/ */
...@@ -335,3 +348,41 @@ function taxonomy_update_8006() { ...@@ -335,3 +348,41 @@ function taxonomy_update_8006() {
->execute(); ->execute();
} }
} }
/**
* Update taxonomy_term_reference field tables to use target_id instead of tid.
*/
function taxonomy_update_8007() {
foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) {
$field_config = config($config_name);
// Only update taxonomy reference fields that use the default SQL storage.
if ($field_config->get('type') == 'taxonomy_term_reference' && $field_config->get('storage.type') == 'field_sql_storage') {
$field = new Field($field_config->get());
$tables = array(
_field_sql_storage_tablename($field),
_field_sql_storage_revision_tablename($field),
);
foreach ($tables as $table_name) {
db_change_field($table_name, $field->id() . '_tid', $field->id() . '_target_id', array(
'description' => 'The ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
));
// Change the index.
db_drop_index($table_name, $field->id() . '_tid');
db_add_index($table_name, $field->id() . '_target_id', array($field->id() . '_target_id'));
}
// Update the indexes in field config as well.
$indexes = $field_config->get('indexes');
unset($indexes['tid']);
$indexes['target_id'] = array('target_id');
$field_config->set('indexes', $indexes);
$field_config->save();
}
}
}
...@@ -948,8 +948,8 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan ...@@ -948,8 +948,8 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan
// Build an array of existing term IDs so they can be loaded with // Build an array of existing term IDs so they can be loaded with
// taxonomy_term_load_multiple(); // taxonomy_term_load_multiple();
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
if (!empty($item['tid']) && $item['tid'] != 'autocreate') { if (!empty($item['target_id']) && $item['target_id'] != 'autocreate') {
$tids[] = $item['tid']; $tids[] = $item['target_id'];
} }
} }
if (!empty($tids)) { if (!empty($tids)) {
...@@ -959,12 +959,12 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan ...@@ -959,12 +959,12 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan
// allowed values for this field. // allowed values for this field.
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
$validate = TRUE; $validate = TRUE;
if (!empty($item['tid']) && $item['tid'] != 'autocreate') { if (!empty($item