diff --git a/modules/comment/comment.module b/modules/comment/comment.module index fdad7b0..3e332cf 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -739,7 +739,7 @@ function comment_node_page_additions($node) { // Append comment form if needed. if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) { - $build = drupal_get_form("comment_node_{$node->type}_form", entity_construct('comment', array('nid' => $node->nid))); + $build = drupal_get_form("comment_node_{$node->type}_form", entity_create('comment', array('nid' => $node->nid))); $additions['comment_form'] = $build; } diff --git a/modules/comment/comment.pages.inc b/modules/comment/comment.pages.inc index 7193fb1..b176105 100644 --- a/modules/comment/comment.pages.inc +++ b/modules/comment/comment.pages.inc @@ -35,7 +35,7 @@ function comment_reply($node, $pid = NULL) { // The user is previewing a comment prior to submitting it. if ($op == t('Preview')) { if (user_access('post comments')) { - $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", entity_construct('comment', array('pid' => $pid, 'nid' => $node->nid))); + $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", entity_create('comment', array('pid' => $pid, 'nid' => $node->nid))); } else { drupal_set_message(t('You are not authorized to post comments.'), 'error'); @@ -86,7 +86,7 @@ function comment_reply($node, $pid = NULL) { drupal_goto("node/$node->nid"); } elseif (user_access('post comments')) { - $comment = entity_construct('comment', array('nid' => $node->nid, 'pid' => $pid)); + $comment = entity_create('comment', array('nid' => $node->nid, 'pid' => $pid)); $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", $comment); } else { diff --git a/modules/comment/comment.test b/modules/comment/comment.test index cc3dcd4..2771bc4 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -87,7 +87,7 @@ class CommentHelperCase extends DrupalWebTestCase { } if (isset($match[1])) { - return entity_construct('comment', array('id' => $match[1], 'subject' => $subject, 'comment' => $comment)); + return entity_create('comment', array('id' => $match[1], 'subject' => $subject, 'comment' => $comment)); } } @@ -269,7 +269,7 @@ class CommentHelperCase extends DrupalWebTestCase { // Create a new comment. This helper function may be run with different // comment settings so use comment_save() to avoid complex setup. - $comment = entity_construct('comment', array( + $comment = entity_create('comment', array( 'cid' => NULL, 'nid' => $this->node->nid, 'node_type' => $this->node->type, @@ -661,7 +661,7 @@ class CommentInterfaceTest extends CommentHelperCase { if ($info['comment count']) { // Create a comment via CRUD API functionality, since // $this->postComment() relies on actual user permissions. - $comment = entity_construct('comment', array( + $comment = entity_create('comment', array( 'cid' => NULL, 'nid' => $this->node->nid, 'node_type' => $this->node->type, @@ -1463,7 +1463,7 @@ class CommentApprovalTest extends CommentHelperCase { // Get unapproved comment id. $this->drupalLogin($this->admin_user); $anonymous_comment4 = $this->getUnapprovedComment($subject); - $anonymous_comment4 = entity_construct('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body)); + $anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body)); $this->drupalLogout(); $this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.')); @@ -1527,7 +1527,7 @@ class CommentApprovalTest extends CommentHelperCase { // Get unapproved comment id. $this->drupalLogin($this->admin_user); $anonymous_comment4 = $this->getUnapprovedComment($subject); - $anonymous_comment4 = entity_construct('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body)); + $anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body)); $this->drupalLogout(); $this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.')); diff --git a/modules/entity/entity.class.inc b/modules/entity/entity.class.inc index 001bcdd..3b8f5aa 100644 --- a/modules/entity/entity.class.inc +++ b/modules/entity/entity.class.inc @@ -228,8 +228,8 @@ class Entity implements EntityInterface { if (isset($this->entityInfo['label callback']) && function_exists($this->entityInfo['label callback'])) { $label = $this->entityInfo['label callback']($this->entityType, $this); } - elseif (!empty($this->entityInfo['entity keys']['label']) && isset($entity->{$this->entityInfo['entity keys']['label']})) { - $label = $entity->{$this->entityInfo['entity keys']['label']}; + elseif (!empty($this->entityInfo['entity keys']['label']) && isset($this->{$this->entityInfo['entity keys']['label']})) { + $label = $this->{$this->entityInfo['entity keys']['label']}; } return $label; } @@ -323,4 +323,3 @@ class Entity implements EntityInterface { $this->setUp(); } } - diff --git a/modules/entity/entity.module b/modules/entity/entity.module index f8daee1..d299781 100644 --- a/modules/entity/entity.module +++ b/modules/entity/entity.module @@ -185,8 +185,8 @@ function entity_create_stub_entity($entity_type, $ids) { if (!empty($info['entity keys']['bundle']) && isset($ids[2])) { $values[$info['entity keys']['bundle']] = $ids[2]; } - // @todo: Once all entities are converted, just rely on entity_construct(). - return isset($info['entity class']) ? entity_construct($entity_type, $values) : (object) $values; + // @todo: Once all entities are converted, just rely on entity_create(). + return isset($info['entity class']) ? entity_create($entity_type, $values) : (object) $values; } /** @@ -269,7 +269,7 @@ function entity_delete_multiple($entity_type, $ids) { } /** - * Construct a new entity object. + * Construct a new entity object, without saving it to the database. * * @param $entity_type * The type of the entity. @@ -280,7 +280,7 @@ function entity_delete_multiple($entity_type, $ids) { * @return EntityInterface * A new entity object. */ -function entity_construct($entity_type, array $values) { +function entity_create($entity_type, array $values) { $info = entity_get_info($entity_type) + array('entity class' => 'Entity'); $class = $info['entity class']; return new $class($values, $entity_type); @@ -476,4 +476,3 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st * Exception thrown when a malformed entity is passed. */ class EntityMalformedException extends Exception { } - diff --git a/modules/entity/tests/entity.test b/modules/entity/tests/entity.test index 9dd0247..c435541 100644 --- a/modules/entity/tests/entity.test +++ b/modules/entity/tests/entity.test @@ -29,11 +29,11 @@ class EntityAPITestCase extends DrupalWebTestCase { $user1 = $this->drupalCreateUser(); // Create some test entities. - $entity = entity_construct('entity_test', array('name' => 'test', 'uid' => $user1->uid)); + $entity = entity_create('entity_test', array('name' => 'test', 'uid' => $user1->uid)); $entity->save(); - $entity = entity_construct('entity_test', array('name' => 'test2', 'uid' => $user1->uid)); + $entity = entity_create('entity_test', array('name' => 'test2', 'uid' => $user1->uid)); $entity->save(); - $entity = entity_construct('entity_test', array('name' => 'test', 'uid' => NULL)); + $entity = entity_create('entity_test', array('name' => 'test', 'uid' => NULL)); $entity->save(); $entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test'))); diff --git a/modules/entity/tests/entity_crud_hook_test.test b/modules/entity/tests/entity_crud_hook_test.test index 1663206..782201e 100644 --- a/modules/entity/tests/entity_crud_hook_test.test +++ b/modules/entity/tests/entity_crud_hook_test.test @@ -66,7 +66,7 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { node_save($node); $nid = $node->nid; - $comment = entity_construct('comment', array( + $comment = entity_create('comment', array( 'cid' => NULL, 'pid' => 0, 'nid' => $nid,