Commit fb08e2f2 authored by Dries's avatar Dries

Issue #1801304 by Amitaibu, amateescu, effulgentsia, tim.plunkett, EclipseGc,...

Issue #1801304 by Amitaibu, amateescu, effulgentsia, tim.plunkett, EclipseGc, Fabianx, Cottser: Added Entity reference field.
parent db8a42c5
......@@ -206,6 +206,10 @@ Database Logging module
Edit module
- Wim Leers 'Wim Leers' http://drupal.org/user/99777
Entity Reference module
- Amitai Burstein 'Amitaibu' http://drupal.org/user/57511
- Andrei Mateescu 'amateescu' http://drupal.org/user/729614
Field module
- Yves Chedemois 'yched' http://drupal.org/user/39567
- Barry Jaspan 'bjaspan' http://drupal.org/user/46413
......
......@@ -8,13 +8,12 @@
namespace Drupal\Core\Entity\Field\Type;
use Drupal\Core\Entity\Field\FieldItemBase;
use InvalidArgumentException;
/**
* Defines the 'entityreference_field' entity field item.
* Defines the 'entity_reference' entity field item.
*
* Available settings (below the definition's 'settings' key) are:
* - entity type: (required) The entity type to reference.
* Required settings (below the definition's 'settings' key) are:
* - target_type: The entity type to reference.
*/
class EntityReferenceItem extends FieldItemBase {
......@@ -32,32 +31,32 @@ class EntityReferenceItem extends FieldItemBase {
*/
public function getPropertyDefinitions() {
// Definitions vary by entity type, so key them by entity type.
$entity_type = $this->definition['settings']['entity type'];
$target_type = $this->definition['settings']['target_type'];
if (!isset(static::$propertyDefinitions[$entity_type])) {
static::$propertyDefinitions[$entity_type]['value'] = array(
if (!isset(self::$propertyDefinitions[$target_type])) {
static::$propertyDefinitions[$target_type]['target_id'] = array(
// @todo: Lookup the entity type's ID data type and use it here.
'type' => 'integer',
'label' => t('Entity ID'),
);
static::$propertyDefinitions[$entity_type]['entity'] = array(
static::$propertyDefinitions[$target_type]['entity'] = array(
'type' => 'entity',
'constraints' => array(
'entity type' => $entity_type,
'entity type' => $target_type,
),
'label' => t('Entity'),
'description' => t('The referenced entity'),
// The entity object is computed out of the entity id.
// The entity object is computed out of the entity ID.
'computed' => TRUE,
'read-only' => FALSE,
'settings' => array('id source' => 'value'),
'settings' => array('id source' => 'target_id'),
);
}
return static::$propertyDefinitions[$entity_type];
return static::$propertyDefinitions[$target_type];
}
/**
* Overrides FieldItemBase::setValue().
* Overrides \Drupal\Core\Entity\Field\FieldItemBase::setValue().
*/
public function setValue($values) {
// Treat the values as property value of the entity field, if no array
......@@ -68,8 +67,8 @@ public function setValue($values) {
// Entity is computed out of the ID, so we only need to update the ID. Only
// set the entity field if no ID is given.
if (isset($values['value'])) {
$this->properties['value']->setValue($values['value']);
if (isset($values['target_id'])) {
$this->properties['target_id']->setValue($values['target_id']);
}
elseif (isset($values['entity'])) {
$this->properties['entity']->setValue($values['entity']);
......@@ -77,9 +76,17 @@ public function setValue($values) {
else {
$this->properties['entity']->setValue(NULL);
}
unset($values['entity'], $values['value']);
unset($values['entity'], $values['target_id']);
if ($values) {
throw new InvalidArgumentException('Property ' . key($values) . ' is unknown.');
throw new \InvalidArgumentException('Property ' . key($values) . ' is unknown.');
}
}
/**
* Overrides \Drupal\Core\Entity\Field\FieldItemBase::get().
*/
public function get($property_name) {
$property_name = ($property_name == 'value') ? 'target_id' : $property_name;
return parent::get($property_name);
}
}
......@@ -124,7 +124,7 @@ function comment_admin_overview($form, &$form_state, $arg) {
'data' => array(
'#type' => 'link',
'#title' => $node_title,
'#href' => 'node/' . $comment->nid->value,
'#href' => 'node/' . $comment->nid->target_id,
),
),
'changed' => format_date($comment->changed->value, 'short'),
......@@ -293,7 +293,7 @@ function comment_confirm_delete($form, &$form_state, Comment $comment) {
return confirm_form(
$form,
t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject->value)),
'node/' . $comment->nid->value,
'node/' . $comment->nid->target_id,
t('Any replies to this comment will be lost. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
......@@ -312,5 +312,5 @@ function comment_confirm_delete_submit($form, &$form_state) {
// Clear the cache so an anonymous user sees that his comment was deleted.
cache_invalidate_tags(array('content' => TRUE));
$form_state['redirect'] = "node/{$comment->nid->value}";
$form_state['redirect'] = "node/{$comment->nid->target_id}";
}
......@@ -34,7 +34,7 @@ function hook_comment_presave(Drupal\comment\Comment $comment) {
*/
function hook_comment_insert(Drupal\comment\Comment $comment) {
// Reindex the node when comments are added.
search_touch_node($comment->nid->value);
search_touch_node($comment->nid->target_id);
}
/**
......@@ -45,7 +45,7 @@ function hook_comment_insert(Drupal\comment\Comment $comment) {
*/
function hook_comment_update(Drupal\comment\Comment $comment) {
// Reindex the node when comments are updated.
search_touch_node($comment->nid->value);
search_touch_node($comment->nid->target_id);
}
/**
......
......@@ -945,7 +945,7 @@ function comment_links(Comment $comment, Node $node) {
);
$links['comment-reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/{$comment->nid->value}/{$comment->id()}",
'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}",
'html' => TRUE,
);
if ($comment->status->value == COMMENT_NOT_PUBLISHED) {
......@@ -967,7 +967,7 @@ function comment_links(Comment $comment, Node $node) {
}
$links['comment-reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/{$comment->nid->value}/{$comment->id()}",
'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}",
'html' => TRUE,
);
}
......@@ -1322,7 +1322,7 @@ function comment_user_cancel($edit, $account, $method) {
case 'user_cancel_reassign':
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
foreach ($comments as $comment) {
$comment->uid->value = 0;
$comment->uid->target_id = 0;
comment_save($comment);
}
break;
......@@ -1357,7 +1357,7 @@ function comment_access($op, Comment $comment) {
global $user;
if ($op == 'edit') {
return ($user->uid && $user->uid == $comment->uid->value && $comment->status->value == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments');
return ($user->uid && $user->uid == $comment->uid->target_id && $comment->status->value == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments');
}
}
......@@ -1560,7 +1560,7 @@ function comment_preview(Comment $comment) {
}
if (!empty($account->uid)) {
$comment->uid->value = $account->uid;
$comment->uid->target_id = $account->uid;
$comment->name->value = check_plain($account->name);
}
elseif (empty($comment->name->value)) {
......@@ -1576,7 +1576,7 @@ function comment_preview(Comment $comment) {
$preview_build['comment_preview'] = $comment_build;
}
if ($comment->pid->value) {
if ($comment->pid->target_id) {
$build = array();
$comment = $comment->pid->entity;
if ($comment && $comment->status->value == COMMENT_PUBLISHED) {
......@@ -1665,7 +1665,7 @@ function template_preprocess_comment(&$variables) {
$variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));
if ($comment->pid->value) {
if ($comment->pid->target_id) {
// Fetch and store the parent comment information for use in templates.
$comment_parent = $comment->pid->entity;
$account_parent = comment_prepare_author($comment);
......@@ -1720,14 +1720,14 @@ function template_preprocess_comment(&$variables) {
if ($variables['new']) {
$variables['attributes']['class'][] = 'new';
}
if (!$comment->uid->value) {
if (!$comment->uid->target_id) {
$variables['attributes']['class'][] = 'by-anonymous';
}
else {
if ($comment->uid->value == $variables['node']->uid) {
if ($comment->uid->target_id == $variables['node']->uid) {
$variables['attributes']['class'][] = 'by-node-author';
}
if ($comment->uid->value == $variables['user']->uid) {
if ($comment->uid->target_id == $variables['user']->uid) {
$variables['attributes']['class'][] = 'by-viewer';
}
}
......
......@@ -59,7 +59,7 @@ function comment_reply(Node $node, $pid = NULL) {
if ($comment->status->value == COMMENT_PUBLISHED) {
// If that comment exists, make sure that the current comment and the
// parent comment both belong to the same parent node.
if ($comment->nid->value != $node->nid) {
if ($comment->nid->target_id != $node->nid) {
// Attempting to reply to a comment not belonging to the current nid.
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
drupal_goto("node/$node->nid");
......@@ -121,7 +121,7 @@ function comment_approve($cid) {
comment_save($comment);
drupal_set_message(t('Comment approved.'));
drupal_goto('node/' . $comment->nid->value);
drupal_goto('node/' . $comment->nid->target_id);
}
throw new NotFoundHttpException();
}
......@@ -131,13 +131,13 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'name':
$name = ($comment->uid->value == 0) ? config('user.settings')->get('anonymous') : $comment->name->value;
$name = ($comment->uid->target_id == 0) ? config('user.settings')->get('anonymous') : $comment->name->value;
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
break;
case 'mail':
if ($comment->uid->value != 0) {
$account = user_load($comment->uid->value);
if ($comment->uid->target_id != 0) {
$account = user_load($comment->uid->target_id);
$mail = $account->mail;
}
else {
......@@ -175,8 +175,8 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'parent':
if (!empty($comment->pid->value)) {
$parent = comment_load($comment->pid->value);
if (!empty($comment->pid->target_id)) {
$parent = comment_load($comment->pid->target_id);
$replacements[$original] = $sanitize ? filter_xss($parent->subject) : $parent->subject;
}
break;
......
......@@ -37,8 +37,8 @@ public function form(array $form, array &$form_state, EntityInterface $comment)
// If not replying to a comment, use our dedicated page callback for new
// comments on nodes.
if (!$comment->id() && !$comment->pid->value) {
$form['#action'] = url('comment/reply/' . $comment->nid->value);
if (!$comment->id() && !$comment->pid->target_id) {
$form['#action'] = url('comment/reply/' . $comment->nid->target_id);
}
if (isset($form_state['comment_preview'])) {
......@@ -163,7 +163,7 @@ public function form(array $form, array &$form_state, EntityInterface $comment)
// Used for conditional validation of author fields.
$form['is_anonymous'] = array(
'#type' => 'value',
'#value' => ($comment->id() ? !$comment->uid->value : !$user->uid),
'#value' => ($comment->id() ? !$comment->uid->target_id : !$user->uid),
);
// Make the comment inherit the current content language unless specifically
......@@ -175,7 +175,8 @@ public function form(array $form, array &$form_state, EntityInterface $comment)
// Add internal comment properties.
foreach (array('cid', 'pid', 'nid', 'uid', 'node_type', 'langcode') as $key) {
$form[$key] = array('#type' => 'value', '#value' => $comment->$key->value);
$key_name = key($comment->$key->offsetGet(0)->getProperties());
$form[$key] = array('#type' => 'value', '#value' => $comment->$key->{$key_name});
}
return parent::form($form, $form_state, $comment);
......@@ -275,7 +276,7 @@ public function submit(array $form, array &$form_state) {
// @todo Too fragile. Should be prepared and stored in comment_form()
// already.
if (!$comment->is_anonymous && !empty($comment->name->value) && ($account = user_load_by_name($comment->name->value))) {
$comment->uid->value = $account->uid;
$comment->uid->target_id = $account->uid;
}
// If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default.
......
......@@ -31,7 +31,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang
// Pre-load associated users into cache to leverage multiple loading.
$uids = array();
foreach ($entities as $entity) {
$uids[] = $entity->uid->value;
$uids[] = $entity->uid->target_id;
}
user_load_multiple(array_unique($uids));
......@@ -40,13 +40,13 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang
// Load all nodes of all comments at once.
$nids = array();
foreach ($entities as $entity) {
$nids[$entity->nid->value] = $entity->nid->value;
$nids[$entity->nid->target_id] = $entity->nid->target_id;
}
$nodes = node_load_multiple($nids);
foreach ($entities as $entity) {
if (isset($nodes[$entity->nid->value])) {
$node = $nodes[$entity->nid->value];
if (isset($nodes[$entity->nid->target_id])) {
$node = $nodes[$entity->nid->target_id];
}
else {
throw new \InvalidArgumentException(t('Invalid node for comment.'));
......
......@@ -91,10 +91,10 @@ protected function preSave(EntityInterface $comment) {
// is extended in a faulty manner.
throw new LogicException('preSave is called again without calling postSave() or releaseThreadLock()');
}
if ($comment->pid->value == 0) {
if ($comment->pid->target_id == 0) {
// This is a comment with no parent comment (depth 0): we start
// by retrieving the maximum thread level.
$max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid->value))->fetchField();
$max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid->target_id))->fetchField();
// Strip the "/" from the end of the thread.
$max = rtrim($max, '/');
// We need to get the value at the correct depth.
......@@ -114,7 +114,7 @@ protected function preSave(EntityInterface $comment) {
// Get the max value in *this* thread.
$max = db_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array(
':thread' => $parent->thread->value . '.%',
':nid' => $comment->nid->value,
':nid' => $comment->nid->target_id,
))->fetchField();
if ($max == '') {
......@@ -137,7 +137,7 @@ protected function preSave(EntityInterface $comment) {
// has the lock, just move to the next integer.
do {
$thread = $prefix . comment_int_to_alphadecimal(++$n) . '/';
} while (!lock()->acquire("comment:{$comment->nid->value}:$thread"));
} while (!lock()->acquire("comment:{$comment->nid->target_id}:$thread"));
$this->threadLock = $thread;
}
if (empty($comment->created->value)) {
......@@ -148,7 +148,7 @@ protected function preSave(EntityInterface $comment) {
}
// We test the value with '===' because we need to modify anonymous
// users as well.
if ($comment->uid->value === $user->uid && isset($user->name)) {
if ($comment->uid->target_id === $user->uid && isset($user->name)) {
$comment->name->value = $user->name;
}
// Add the values which aren't passed into the function.
......@@ -163,7 +163,7 @@ protected function preSave(EntityInterface $comment) {
protected function postSave(EntityInterface $comment, $update) {
$this->releaseThreadLock();
// Update the {node_comment_statistics} table prior to executing the hook.
$this->updateNodeStatistics($comment->nid->value);
$this->updateNodeStatistics($comment->nid->target_id);
if ($comment->status->value == COMMENT_PUBLISHED) {
module_invoke_all('comment_publish', $comment);
}
......@@ -181,7 +181,7 @@ protected function postDelete($comments) {
comment_delete_multiple($child_cids);
foreach ($comments as $comment) {
$this->updateNodeStatistics($comment->nid->value);
$this->updateNodeStatistics($comment->nid->target_id);
}
}
......@@ -274,14 +274,14 @@ public function baseFieldDefinitions() {
$properties['pid'] = array(
'label' => t('Parent ID'),
'description' => t('The parent comment ID if this is a reply to a comment.'),
'type' => 'entityreference_field',
'settings' => array('entity type' => 'comment'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'comment'),
);
$properties['nid'] = array(
'label' => t('Node ID'),
'description' => t('The ID of the node of which this comment is a reply.'),
'type' => 'entityreference_field',
'settings' => array('entity type' => 'node'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'node'),
'required' => TRUE,
);
$properties['langcode'] = array(
......@@ -297,8 +297,8 @@ public function baseFieldDefinitions() {
$properties['uid'] = array(
'label' => t('User ID'),
'description' => t('The user ID of the comment author.'),
'type' => 'entityreference_field',
'settings' => array('entity type' => 'user'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'user'),
);
$properties['name'] = array(
'label' => t('Name'),
......
......@@ -28,7 +28,7 @@ public function getValue($langcode = NULL) {
}
$field = $this->parent->getParent();
$entity = $field->getParent();
$this->value = node_mark($entity->nid->value, $entity->changed->value);
$this->value = node_mark($entity->nid->target_id, $entity->changed->value);
}
return $this->value;
}
......
......@@ -180,7 +180,7 @@ class Comment extends EntityNG implements ContentEntityInterface {
protected $values = array(
'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))),
'name' => array(LANGUAGE_DEFAULT => array(0 => array('value' => ''))),
'uid' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))),
'uid' => array(LANGUAGE_DEFAULT => array(0 => array('target_id' => 0))),
);
/**
......
<?php
/**
* @file
* Contains \Drupal\comment\Plugin\entity_reference\selection\CommentSelection.
*/
namespace Drupal\comment\Plugin\entity_reference\selection;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase;
/**
* Provides specific access control for the comment entity type.
*
* @Plugin(
* id = "comment_default",
* module = "comment",
* label = @Translation("Comment selection"),
* entity_types = {"comment"},
* group = "default",
* weight = 1
* )
*/
class CommentSelection extends SelectionBase {
/**
* Overrides SelectionBase::buildEntityQuery().
*/
public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
// Adding the 'comment_access' tag is sadly insufficient for comments:
// core requires us to also know about the concept of 'published' and
// 'unpublished'.
if (!user_access('administer comments')) {
$query->condition('status', COMMENT_PUBLISHED);
}
return $query;
}
/**
* Overrides SelectionBase::entityQueryAlter().
*/
public function entityQueryAlter(SelectInterface $query) {
$tables = $query->getTables();
$base_table = $tables['base_table']['alias'];
// The Comment module doesn't implement any proper comment access,
// and as a consequence doesn't make sure that comments cannot be viewed
// when the user doesn't have access to the node.
$node_alias = $query->innerJoin('node', 'n', '%alias.nid = ' . $base_table . '.nid');
// Pass the query to the node access control.
$this->reAlterQuery($query, 'node_access', $node_alias);
// Alas, the comment entity exposes a bundle, but doesn't have a bundle
// column in the database. We have to alter the query ourselves to go fetch
// the bundle.
$conditions = &$query->conditions();
foreach ($conditions as $key => &$condition) {
if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'node_type') {
$condition['field'] = $node_alias . '.type';
foreach ($condition['value'] as &$value) {
if (substr($value, 0, 13) == 'comment_node_') {
$value = substr($value, 13);
}
}
break;
}
}
// Passing the query to node_query_node_access_alter() is sadly
// insufficient for nodes.
// @see SelectionEntityTypeNode::entityQueryAlter()
if (!user_access('bypass node access') && !count(module_implements('node_grants'))) {
$query->condition($node_alias . '.status', 1);
}
}
}
......@@ -67,7 +67,7 @@ function testCommentInterface() {
// Test changing the comment author to "Anonymous".
$this->drupalGet('comment/' . $comment->id() . '/edit');
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => ''));
$this->assertTrue(empty($comment->name->value) && $comment->uid->value == 0, 'Comment author successfully changed to anonymous.');
$this->assertTrue(empty($comment->name->value) && $comment->uid->target_id == 0, 'Comment author successfully changed to anonymous.');
// Test changing the comment author to an unverified user.
$random_name = $this->randomName();
......@@ -79,7 +79,7 @@ function testCommentInterface() {
// Test changing the comment author to a verified user.
$this->drupalGet('comment/' . $comment->id() . '/edit');
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->name));
$this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->value == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
$this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->target_id == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
$this->drupalLogout();
......@@ -92,7 +92,7 @@ function testCommentInterface() {
$reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
$reply_loaded = comment_load($reply->id());
$this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
$this->assertEqual($comment->id(), $reply_loaded->pid->value, 'Pid of a reply to a comment is set correctly.');
$this->assertEqual($comment->id(), $reply_loaded->pid->target_id, 'Pid of a reply to a comment is set correctly.');
$this->assertEqual(rtrim($comment->thread->value, '/') . '.00/', $reply_loaded->thread->value, 'Thread of reply grows correctly.');
// Second reply to comment #3 creating comment #4.
......
......@@ -61,11 +61,11 @@ function testCommentTokenReplacement() {
$tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options);
$tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created->value, 2, $language_interface->langcode);
$tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed->value, 2, $language_interface->langcode);
$tests['[comment:parent:cid]'] = $comment->pid->value;
$tests['[comment:parent:cid]'] = $comment->pid->target_id;
$tests['[comment:parent:title]'] = check_plain($parent_comment->subject->value);
$tests['[comment:node:nid]'] = $comment->nid->value;
$tests['[comment:node:nid]'] = $comment->nid->target_id;
$tests['[comment:node:title]'] = check_plain($node->title);
$tests['[comment:author:uid]'] = $comment->uid->value;
$tests['[comment:author:uid]'] = $comment->uid->target_id;
$tests['[comment:author:name]'] = check_plain($this->admin_user->name);
// Test to make sure that we generated something for each token.
......
......@@ -78,8 +78,8 @@ public function setUp() {
// Create some comments and attach them to the created node.
for ($i = 0; $i < $this->masterDisplayResults; $i++) {
$comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->type));
$comment->uid->value = 0;
$comment->nid->value = $this->node->nid;
$comment->uid->target_id = 0;
$comment->nid->target_id = $this->node->nid;
$comment->subject->value = 'Test comment ' . $i;
$comment->comment_body->value = 'Test body ' . $i;
$comment->comment_body->format = 'full_html';
......@@ -107,7 +107,7 @@ public function testBlockDisplay() {
);
$expected_result = array();
foreach (array_values($this->commentsCreated) as $key => $comment) {
$expected_result[$key]['nid'] = $comment->nid->value;
$expected_result[$key]['nid'] = $comment->nid->target_id;
$expected_result[$key]['subject'] = $comment->subject->value;
$expected_result[$key]['cid'] = $comment->id();
$expected_result[$key]['changed'] = $comment->changed->value;
......@@ -139,7 +139,7 @@ public function testPageDisplay() {
);
$expected_result = array();
foreach (array_values($this->commentsCreated) as $key => $comment) {
$expected_result[$key]['nid'] = $comment->nid->value;
$expected_result[$key]['nid'] = $comment->nid->target_id;
$expected_result[$key]['subject'] = $comment->subject->value;
$expected_result[$key]['changed'] = $comment->changed->value;
$expected_result[$key]['created'] = $comment->created->value;
......
.entity_reference-settings {
margin-right: 1.5em;
}
.entity_reference-settings {
margin-left: 1.5em; /* LTR */
}
name = Entity Reference
description = Provides a field that can reference other entities.
package = Core
version = VERSION
core = 8.x
dependencies[] = field
<?php
/**
* @file
* Install, update and uninstall functions for the Entity Reference
* module.
*/
/**
* Implements hook_field_schema().
*/
function entity_reference_field_schema($field) {
$schema = array(
'columns' => array(
'target_id' => array(
'description' => 'The ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'revision_id' => array(
'description' => 'The revision ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'target_id' => array('target_id'),
),
'foreign keys' => array(),
);
// Create a foreign key to the target entity type base type.
// @todo It's still not safe to call entity_get_info() in here.
// see http://drupal.org/node/1847582
// $entity_type = $field['settings']['target_type'];
// $entity_info = entity_get_info($entity_type);
//
// $base_table = $entity_info['base_table'];
// $id_column = $entity_info['entity_keys']['id'];