diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 60eb5ff..3298657 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -291,6 +291,8 @@ public function baseFieldDefinitions() { 'label' => t('Entity ID'), 'description' => t('The ID of the entity of which this comment is a reply.'), 'type' => 'entity_reference_field', + // @todo Implement a 'class' to get referenced entity at runtime. + 'class' => '\Drupal\comment\Type\CommentEntityItem', 'settings' => array('target_type' => 'node'), 'required' => TRUE, ); diff --git a/core/modules/comment/lib/Drupal/comment/Type/CommentEntityItem.php b/core/modules/comment/lib/Drupal/comment/Type/CommentEntityItem.php new file mode 100644 index 0000000..16062a2 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Type/CommentEntityItem.php @@ -0,0 +1,58 @@ + 'entity_reference', + 'settings' => array('target_type' => $entity_type), + ); + } + return static::$propertyDefinitions; + } + + /** + * {@inheritdoc} + */ + public function getValue($langcode = NULL) { + if (!isset($this->value)) { + if (!isset($this->parent)) { + throw new InvalidArgumentException('Computed properties require context for computation.'); + } + $field = $this->parent->getParent(); + $entity = $field->getParent(); + $this->value = $entity; + } + return $this->value; + } + +}