From afaae81043177b87edb50f79bf2ea34332e19f83 Mon Sep 17 00:00:00 2001 From: Chris Skene Date: Sun, 4 Nov 2012 19:57:20 +1100 Subject: [PATCH] Issue #1042822 by xjm, manimejia, tstoeckler, tim.plunkett, xtfer: Added Developers need an $entity->entity_type() property. --- includes/entity.inc | 5 +++++ modules/simpletest/tests/entity_crud_hook_test.test | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/includes/entity.inc b/includes/entity.inc index 2fefd59..88eabad 100644 --- a/includes/entity.inc +++ b/includes/entity.inc @@ -223,6 +223,11 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { $entities = $passed_ids; } + // Store the entity type in each entity. + foreach ($entities as $entity) { + $entity->entity_type = $this->entityType; + } + return $entities; } diff --git a/modules/simpletest/tests/entity_crud_hook_test.test b/modules/simpletest/tests/entity_crud_hook_test.test index 178e34d..964dc7d 100644 --- a/modules/simpletest/tests/entity_crud_hook_test.test +++ b/modules/simpletest/tests/entity_crud_hook_test.test @@ -97,6 +97,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type comment'); $this->assertHookMessage('entity_crud_hook_test_comment_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($comment->entity_type, 'comment', t('Entity type is set to %type', array('%type' => 'comment'))); + $_SESSION['entity_crud_hook_test'] = array(); $comment->subject = 'New subject'; comment_save($comment); @@ -143,6 +146,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type file'); $this->assertHookMessage('entity_crud_hook_test_file_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($file->entity_type, 'file', t('Entity type is set to %type', array('%type' => 'file'))); + $_SESSION['entity_crud_hook_test'] = array(); $file->filename = 'new.entity_crud_hook_test.file'; file_save($file); @@ -189,6 +195,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type node'); $this->assertHookMessage('entity_crud_hook_test_node_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($node->entity_type, 'node', t('Entity type is set to %type', array('%type' => 'node'))); + $_SESSION['entity_crud_hook_test'] = array(); $node->title = 'New title'; node_save($node); @@ -237,6 +246,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type taxonomy_term'); $this->assertHookMessage('entity_crud_hook_test_taxonomy_term_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($term->entity_type, 'taxonomy_term', t('Entity type is set to %type', array('%type' => 'taxonomy_term'))); + $_SESSION['entity_crud_hook_test'] = array(); $term->name = 'New name'; taxonomy_term_save($term); @@ -277,6 +289,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type taxonomy_vocabulary'); $this->assertHookMessage('entity_crud_hook_test_taxonomy_vocabulary_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($vocabulary->entity_type, 'taxonomy_vocabulary', t('Entity type is set to %type', array('%type' => 'taxonomy_vocabulary'))); + $_SESSION['entity_crud_hook_test'] = array(); $vocabulary->name = 'New name'; taxonomy_vocabulary_save($vocabulary); @@ -319,6 +334,9 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { $this->assertHookMessage('entity_crud_hook_test_entity_load called for type user'); $this->assertHookMessage('entity_crud_hook_test_user_load called'); + // Check that the entity type is set correctly. + $this->assertEqual($account->entity_type, 'user', t('Entity type is set to %type', array('%type' => 'user'))); + $_SESSION['entity_crud_hook_test'] = array(); $edit['name'] = 'New name'; $account = user_save($account, $edit); -- 1.7.11.1