summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/entity.inc10
-rw-r--r--modules/field/field.test10
-rw-r--r--modules/field/modules/text/text.test6
-rw-r--r--modules/simpletest/tests/field_test.module4
-rw-r--r--modules/system/system.api.php17
-rw-r--r--modules/taxonomy/taxonomy.test2
6 files changed, 36 insertions, 13 deletions
diff --git a/includes/entity.inc b/includes/entity.inc
index e50cf6fb3..ba9175d9a 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -223,8 +223,9 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
/**
* Attach data to entities upon loading.
*
- * This will attach fields, if the entity is fieldable. It also calls
- * hook_TYPE_load() on the loaded entities. For example
+ * This will attach fields, if the entity is fieldable. It calls
+ * hook_entity_load() for modules which need to add data to all entities.
+ * It also calls hook_TYPE_load() on the loaded entities. For example
* hook_node_load() or hook_user_load(). If your hook_TYPE_load()
* expects special parameters apart from the queried entities, you can set
* $this->hookLoadArguments prior to calling the method.
@@ -241,6 +242,11 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
}
}
+ // Call hook_entity_load().
+ foreach (module_implements('entity_load') as $module) {
+ $function = $module . '_entity_load';
+ $function($queried_entities, $this->entityType);
+ }
// Call hook_TYPE_load(). The first argument for hook_TYPE_load() are
// always the queried entities, followed by additional arguments set in
// $this->hookLoadArguments.
diff --git a/modules/field/field.test b/modules/field/field.test
index 86983e35b..49f763bfa 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -1373,7 +1373,7 @@ class FieldFormTestCase extends FieldTestCase {
preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created');
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$this->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was saved');
// Display edit form.
@@ -1386,7 +1386,7 @@ class FieldFormTestCase extends FieldTestCase {
$edit = array("{$this->field_name}[$langcode][0][value]" => $value);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), 'Entity was updated');
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$this->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was updated');
// Empty the field.
@@ -1394,7 +1394,7 @@ class FieldFormTestCase extends FieldTestCase {
$edit = array("{$this->field_name}[$langcode][0][value]" => $value);
$this->drupalPost('test-entity/' . $id . '/edit', $edit, t('Save'));
$this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), 'Entity was updated');
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$this->assertIdentical($entity->{$this->field_name}, array(), 'Field was emptied');
}
@@ -1420,7 +1420,7 @@ class FieldFormTestCase extends FieldTestCase {
preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created');
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$this->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was saved');
// Edit with missing required value.
@@ -1500,7 +1500,7 @@ class FieldFormTestCase extends FieldTestCase {
preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created');
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
ksort($field_values);
$field_values = array_values($field_values);
$this->assertIdentical($entity->{$this->field_name}[$langcode], $field_values, 'Field values were saved in the correct order');
diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test
index b4cc4dfef..2f903e201 100644
--- a/modules/field/modules/text/text.test
+++ b/modules/field/modules/text/text.test
@@ -115,7 +115,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), t('Entity was created'));
// Display the object.
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertText($value, 'Filtered tags are not displayed');
@@ -179,7 +179,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), t('Entity was created'));
// Display the object.
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertNoRaw($value, t('HTML tags are not displayed.'));
@@ -212,7 +212,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), t('Entity was updated'));
// Display the object.
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertRaw($value, t('Value is displayed unfiltered'));
diff --git a/modules/simpletest/tests/field_test.module b/modules/simpletest/tests/field_test.module
index 8bb504389..86a2751ea 100644
--- a/modules/simpletest/tests/field_test.module
+++ b/modules/simpletest/tests/field_test.module
@@ -38,7 +38,7 @@ function field_test_menu() {
'type' => MENU_NORMAL_ITEM,
);
}
- $items['test-entity/%field_test_entity/edit'] = array(
+ $items['test-entity/%field_test_entity_test/edit'] = array(
'title' => 'Edit test entity',
'page callback' => 'field_test_entity_edit',
'page arguments' => array(1),
@@ -193,7 +193,7 @@ function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = FIELD_TEST_B
return $entity;
}
-function field_test_entity_load($ftid, $ftvid = NULL) {
+function field_test_entity_test_load($ftid, $ftvid = NULL) {
// Load basic strucure.
$query = db_select('test_entity', 'fte', array())
->fields('fte')
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index d29a16035..f6b9be1ef 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -150,6 +150,23 @@ function hook_entity_info_alter(&$entity_info) {
}
/**
+ * Act on entities when loaded.
+ *
+ * This is a generic load hook called for all entity types loaded via the
+ * entity API.
+ *
+ * @param $entities
+ * The entities keyed by entity ID.
+ * @param $type
+ * The type of entities being loaded (i.e. node, user, comment).
+ */
+function hook_entity_load($entities, $type) {
+ foreach ($entities as $entity) {
+ $entity->foo = mymodule_add_something($entity, $entity_type);
+ }
+}
+
+/**
* Perform periodic actions.
*
* This hook will only be called if cron.php is run (e.g. by crontab).
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 36fbcabec..e7b41599c 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -757,7 +757,7 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), t('Entity was created'));
// Display the object.
- $entity = field_test_entity_load($id);
+ $entity = field_test_entity_test_load($id);
$entities = array($id => $entity);
field_attach_prepare_view($entity_type, $entities, 'full');
$entity->content = field_attach_view($entity_type, $entity);