Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
298
Merge Requests
298
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
1c7bca0b
Commit
1c7bca0b
authored
Oct 16, 2009
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#605442
by catch: Add a generic hook_entity_load().
parent
92f5a844
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
13 deletions
+36
-13
includes/entity.inc
includes/entity.inc
+8
-2
modules/field/field.test
modules/field/field.test
+5
-5
modules/field/modules/text/text.test
modules/field/modules/text/text.test
+3
-3
modules/simpletest/tests/field_test.module
modules/simpletest/tests/field_test.module
+2
-2
modules/system/system.api.php
modules/system/system.api.php
+17
-0
modules/taxonomy/taxonomy.test
modules/taxonomy/taxonomy.test
+1
-1
No files found.
includes/entity.inc
View file @
1c7bca0b
...
...
@@ -223,8 +223,9 @@ protected function buildQuery() {
/**
* 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 @@ protected function attachLoad(&$queried_entities) {
}
}
// 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.
...
...
modules/field/field.test
View file @
1c7bca0b
...
...
@@ -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'
);
...
...
modules/field/modules/text/text.test
View file @
1c7bca0b
...
...
@@ -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'
));
...
...
modules/simpletest/tests/field_test.module
View file @
1c7bca0b
...
...
@@ -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'
)
...
...
modules/system/system.api.php
View file @
1c7bca0b
...
...
@@ -149,6 +149,23 @@ function hook_entity_info_alter(&$entity_info) {
$entity_info
[
'node'
][
'controller class'
]
=
'MyCustomNodeController'
;
}
/**
* 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.
*
...
...
modules/taxonomy/taxonomy.test
View file @
1c7bca0b
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment