From 0b2c622bfa70e07d414f2900274effee6df48c0d Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 15 Feb 2014 22:40:41 +0000 Subject: [PATCH] Issue #2181593 by klausi, chakrapani, andypost: Convert entity bundle base fields to entity reference. --- .../lib/Drupal/custom_block/Entity/CustomBlock.php | 5 +++-- .../comment/lib/Drupal/comment/Entity/Comment.php | 7 +++---- .../modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php | 9 ++++----- .../taxonomy/Tests/TaxonomyTermReferenceItemTest.php | 2 +- .../lib/Drupal/taxonomy/Tests/TermValidationTest.php | 4 ++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 68c3b102ad5c..12766292ae38 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -188,9 +188,10 @@ public static function baseFieldDefinitions($entity_type) { ->setLabel(t('Subject')) ->setDescription(t('The custom block name.')); - $fields['type'] = FieldDefinition::create('string') + $fields['type'] = FieldDefinition::create('entity_reference') ->setLabel(t('Block type')) - ->setDescription(t('The block type.')); + ->setDescription(t('The block type.')) + ->setSetting('target_type', 'custom_block_type'); $fields['log'] = FieldDefinition::create('string') ->setLabel(t('Revision log message')) diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index a715fb4f4b0b..0d4947941fd4 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -430,11 +430,10 @@ public static function baseFieldDefinitions($entity_type) { ->setLabel(t('Entity type')) ->setDescription(t('The entity type to which this comment is attached.')); - // @todo Convert to aa entity_reference field in - // https://drupal.org/node/2149859. - $fields['field_id'] = FieldDefinition::create('string') + $fields['field_id'] = FieldDefinition::create('entity_reference') ->setLabel(t('Field ID')) - ->setDescription(t('The comment field id.')); + ->setDescription(t('The comment field id.')) + ->setSetting('target_type', 'field_entity'); $fields['field_name'] = FieldDefinition::create('string') ->setLabel(t('Comment field name')) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index d8f503c8a9ee..d4fe2cc093d3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -208,11 +208,10 @@ public static function baseFieldDefinitions($entity_type) { ->setDescription(t('The term UUID.')) ->setReadOnly(TRUE); - // @todo Convert this to an entity_reference field, see - // https://drupal.org/node/2181593 - $fields['vid'] = FieldDefinition::create('string') - ->setLabel(t('Vocabulary ID')) - ->setDescription(t('The ID of the vocabulary to which the term is assigned.')); + $fields['vid'] = FieldDefinition::create('entity_reference') + ->setLabel(t('Vocabulary')) + ->setDescription(t('The vocabulary to which the term is assigned.')) + ->setSetting('target_type', 'taxonomy_vocabulary'); $fields['langcode'] = FieldDefinition::create('language') ->setLabel(t('Language code')) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php index ed631d8420fa..e154c4363cf0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -102,7 +102,7 @@ public function testTaxonomyTermReferenceItem() { // Make sure the computed term reflects updates to the term id. $term2 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), - 'vid' => $this->term->vid->value, + 'vid' => $this->term->bundle(), 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $term2->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermValidationTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermValidationTest.php index dfb9803fe1c0..e36668f3b38b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermValidationTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermValidationTest.php @@ -41,6 +41,10 @@ public function setUp() { * Tests the term validation constraints. */ public function testValidation() { + $this->entityManager->getStorageController('taxonomy_vocabulary')->create(array( + 'vid' => 'tags', + 'name' => 'Tags', + ))->save(); $term = $this->entityManager->getStorageController('taxonomy_term')->create(array( 'name' => 'test', 'vid' => 'tags', -- GitLab