diff --git a/core/lib/Drupal/Core/Entity/Plugin/field/field_type/FloatItem.php b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/FloatItem.php index 6e35ac4..ce571e8 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/field/field_type/FloatItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/FloatItem.php @@ -12,11 +12,11 @@ /** * Defines the 'float' entity field type. * - * @DataType( + * @FieldType( * id = "float", * label = @Translation("Float"), * description = @Translation("An entity field containing an float value."), - * configurable = false, + * configurable = false * ) */ class FloatItem extends FieldItemBase { diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php index 432534f..ea8f916 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/field_type/CommentItem.php @@ -51,11 +51,8 @@ public function getPropertyDefinitions() { 'label' => t('Comment status value'), ), 'cid' => array( - 'type' => 'entity_reference_field', 'label' => t('Last comment ID'), - 'settings' => array( - 'target_type' => 'comment', - ), + 'type' => 'integer', ), 'last_comment_timestamp' => array( 'label' => t('Last comment timestamp'), @@ -68,11 +65,8 @@ public function getPropertyDefinitions() { 'type' => 'string', ), 'last_comment_uid' => array( - 'type' => 'entity_reference_field', + 'type' => 'integer', 'label' => t('Last comment user ID'), - 'settings' => array( - 'target_type' => 'user', - ), ), 'comment_count' => array( 'label' => t('Number of comments'), diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index b9e7c58..5d2632c 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -15,11 +15,16 @@ * Implements hook_field_info_alter(). */ function entity_reference_field_info_alter(&$info) { - if (!\Drupal::moduleHandler()->moduleExists('node')) { - // Fall back to another primary entity type if the Node module is not - // available. - $info['entity_reference']['settings']['target_type'] = 'user'; - } + // Make he entity reference field configurable. + $info['entity_reference']['configurable'] = TRUE; + $info['entity_reference']['class'] = '\Drupal\entity_reference\Plugin\field\field_type\ConfigurableEntityReferenceItem'; + $info['entity_reference']['list_class'] = '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList'; + $info['entity_reference']['settings']['target_type'] = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user'; + $info['entity_reference']['instance_settings']['handler'] = 'default'; + $info['entity_reference']['instance_settings']['handler_settings'] = array(); + $info['entity_reference']['default_widget'] = 'entity_reference_autocomplete'; + $info['entity_reference']['default_formatter'] = 'entity_reference_label'; + $info['entity_reference']['constraints'] = array('ValidReference' => TRUE); } /** @@ -27,7 +32,7 @@ function entity_reference_field_info_alter(&$info) { * * Set the "target_type" property definition for entity reference fields. * - * @see \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem::getPropertyDefinitions() + * @see \Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem::getPropertyDefinitions() * * @param array $info * The property info array as returned by hook_entity_field_info(). diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php index ee5e79a..bf4bbb4 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php @@ -7,33 +7,13 @@ namespace Drupal\entity_reference\Plugin\field\field_type; -use Drupal\Core\Annotation\Translation; -use Drupal\Core\Entity\Annotation\FieldType; -use Drupal\Core\Entity\Field\Type\EntityReferenceItem; use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase; -use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface; use Drupal\field\FieldInterface; /** * Plugin implementation of the 'entity_reference' field type. * - * @FieldType( - * id = "entity_reference", - * label = @Translation("Entity Reference"), - * description = @Translation("This field references another entity."), - * settings = { - * "target_type" = "node" - * }, - * instance_settings = { - * "handler" = "default", - * "handler_settings" = { } - * }, - * default_widget = "entity_reference_autocomplete", - * default_formatter = "entity_reference_label", - * constraints = {"ValidReference" = TRUE} - * ) - * * Extends the Core 'entity_reference' entity field item with properties for * revision ids, labels (for autocreate) and access. * diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php index a4f54f0..a7ab95b 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php @@ -19,7 +19,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR * * @var string */ - protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem'; + protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem'; /** * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 7f6c87e..30fea9e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -536,7 +536,7 @@ public function testEntityConstraintValidation() { $entity->save(); // Create a reference field item and let it reference the entity. $definition = array( - 'type' => 'entity_reference_field', + 'type' => 'field_item:entity_reference', 'settings' => array( 'target_type' => 'entity_test', ), @@ -563,7 +563,7 @@ public function testEntityConstraintValidation() { // Test bundle validation. $definition = array( - 'type' => 'entity_reference_field', + 'type' => 'field_item:entity_reference', 'settings' => array( 'target_type' => 'node', 'target_bundle' => 'article',