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
221
Merge Requests
221
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
38a36d4e
Commit
38a36d4e
authored
Jan 21, 2013
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1253820
follow-up by plach: Missing a few hook implementations + tests.
parent
252f0c8e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
15 deletions
+124
-15
core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
...lib/Drupal/Core/Config/Entity/ConfigStorageController.php
+4
-0
core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
+5
-0
core/modules/comment/lib/Drupal/comment/CommentStorageController.php
...s/comment/lib/Drupal/comment/CommentStorageController.php
+1
-14
core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php
...dules/config/lib/Drupal/config/Tests/ConfigEntityTest.php
+5
-0
core/modules/config/tests/config_test/config_test.module
core/modules/config/tests/config_test/config_test.module
+9
-0
core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
...tem/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
+44
-1
core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
...odules/entity_crud_hook_test/entity_crud_hook_test.module
+56
-0
No files found.
core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
View file @
38a36d4e
...
...
@@ -244,6 +244,10 @@ public function create(array $values) {
$entity
->
{
$this
->
uuidKey
}
=
$uuid
->
generate
();
}
// Modules might need to add or change the data initially held by the new
// entity object, for instance to fill-in default values.
$this
->
invokeHook
(
'create'
,
$entity
);
return
$entity
;
}
...
...
core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
View file @
38a36d4e
...
...
@@ -104,6 +104,11 @@ public function create(array $values) {
$uuid
=
new
Uuid
();
$entity
->
{
$this
->
uuidKey
}
->
value
=
$uuid
->
generate
();
}
// Modules might need to add or change the data initially held by the new
// entity object, for instance to fill-in default values.
$this
->
invokeHook
(
'create'
,
$entity
);
return
$entity
;
}
...
...
core/modules/comment/lib/Drupal/comment/CommentStorageController.php
View file @
38a36d4e
...
...
@@ -55,24 +55,11 @@ protected function attachLoad(&$records, $load_revision = FALSE) {
* Overrides Drupal\Core\Entity\DatabaseStorageControllerNG::create().
*/
public
function
create
(
array
$values
)
{
// We have to determine the bundle first.
if
(
empty
(
$values
[
'node_type'
])
&&
!
empty
(
$values
[
'nid'
]))
{
$node
=
node_load
(
$values
[
'nid'
]);
$values
[
'node_type'
]
=
'comment_node_'
.
$node
->
type
;
}
$comment
=
new
$this
->
entityClass
(
array
(),
$this
->
entityType
,
$values
[
'node_type'
]);
// Set all other given values.
foreach
(
$values
as
$name
=>
$value
)
{
$comment
->
$name
=
$value
;
}
// Assign a new UUID if there is none yet.
if
(
$this
->
uuidKey
&&
!
isset
(
$comment
->
{
$this
->
uuidKey
}))
{
$uuid
=
new
Uuid
();
$comment
->
{
$this
->
uuidKey
}
->
value
=
$uuid
->
generate
();
}
return
$comment
;
return
parent
::
create
(
$values
);
}
/**
...
...
core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php
View file @
38a36d4e
...
...
@@ -175,6 +175,11 @@ function testCRUD() {
$this
->
assertIdentical
(
$config_test
->
id
(),
$new_id
);
$this
->
assertIdentical
(
$config_test
->
getOriginalID
(),
$new_id
);
}
// Test config entity prepopulation.
state
()
->
set
(
'config_test.prepopulate'
,
TRUE
);
$config_test
=
entity_create
(
'config_test'
,
array
(
'foo'
=>
'bar'
));
$this
->
assertEqual
(
$config_test
->
get
(
'foo'
),
'baz'
,
'Initial value correctly populated'
);
}
/**
...
...
core/modules/config/tests/config_test/config_test.module
View file @
38a36d4e
...
...
@@ -137,3 +137,12 @@ function config_test_cache_flush() {
return
array
();
}
/**
* Implements hook_ENTITY_TYPE_create().
*/
function
config_test_config_test_create
(
ConfigTest
$config_test
)
{
if
(
state
()
->
get
(
'config_test.prepopulate'
))
{
$config_test
->
set
(
'foo'
,
'baz'
);
}
}
core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
View file @
38a36d4e
...
...
@@ -36,7 +36,7 @@ class EntityCrudHookTest extends WebTestBase {
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Entity CRUD hooks'
,
'description'
=>
'Tests the invocation of hooks when inserting, loading, updating or deleting an entity.'
,
'description'
=>
'Tests the invocation of hooks when
creating,
inserting, loading, updating or deleting an entity.'
,
'group'
=>
'Entity API'
,
);
}
...
...
@@ -74,6 +74,12 @@ public function testBlockHooks() {
'id'
=>
'stark.test_html_id'
,
'plugin'
=>
'test_html_id'
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_block_create called'
,
'entity_crud_hook_test_entity_create called for type block'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$entity
->
save
();
...
...
@@ -132,6 +138,7 @@ public function testCommentHooks() {
));
$node
->
save
();
$nid
=
$node
->
nid
;
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$comment
=
entity_create
(
'comment'
,
array
(
'node_type'
=>
'node_type_'
.
$node
->
bundle
(),
...
...
@@ -146,6 +153,11 @@ public function testCommentHooks() {
'langcode'
=>
LANGUAGE_NOT_SPECIFIED
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_comment_create called'
,
'entity_crud_hook_test_entity_create called for type comment'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
comment_save
(
$comment
);
...
...
@@ -202,6 +214,12 @@ public function testFileHooks() {
'status'
=>
1
,
'timestamp'
=>
REQUEST_TIME
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_file_create called'
,
'entity_crud_hook_test_entity_create called for type file'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$file
->
save
();
...
...
@@ -258,6 +276,12 @@ public function testNodeHooks() {
'created'
=>
REQUEST_TIME
,
'changed'
=>
REQUEST_TIME
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_node_create called'
,
'entity_crud_hook_test_entity_create called for type node'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$node
->
save
();
...
...
@@ -310,6 +334,7 @@ public function testTaxonomyTermHooks() {
'module'
=>
'entity_crud_hook_test'
,
));
taxonomy_vocabulary_save
(
$vocabulary
);
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$term
=
entity_create
(
'taxonomy_term'
,
array
(
'vid'
=>
$vocabulary
->
id
(),
...
...
@@ -318,6 +343,12 @@ public function testTaxonomyTermHooks() {
'description'
=>
NULL
,
'format'
=>
1
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_taxonomy_term_create called'
,
'entity_crud_hook_test_entity_create called for type taxonomy_term'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
taxonomy_term_save
(
$term
);
...
...
@@ -369,6 +400,12 @@ public function testTaxonomyVocabularyHooks() {
'description'
=>
NULL
,
'module'
=>
'entity_crud_hook_test'
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_taxonomy_vocabulary_create called'
,
'entity_crud_hook_test_entity_create called for type taxonomy_vocabulary'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
taxonomy_vocabulary_save
(
$vocabulary
);
...
...
@@ -420,6 +457,12 @@ public function testUserHooks() {
'status'
=>
1
,
'language'
=>
'en'
,
));
$this
->
assertHookMessageOrder
(
array
(
'entity_crud_hook_test_user_create called'
,
'entity_crud_hook_test_entity_create called for type user'
,
));
$_SESSION
[
'entity_crud_hook_test'
]
=
array
();
$account
->
save
();
...
...
core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
View file @
38a36d4e
...
...
@@ -7,6 +7,62 @@
use
Drupal\Core\Entity\EntityInterface
;
/**
* Implements hook_entity_create().
*/
function
entity_crud_hook_test_entity_create
(
EntityInterface
$entity
)
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called for type '
.
$entity
->
entityType
());
}
/**
* Implements hook_block_create().
*/
function
entity_crud_hook_test_block_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_comment_create().
*/
function
entity_crud_hook_test_comment_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_file_create().
*/
function
entity_crud_hook_test_file_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_node_create().
*/
function
entity_crud_hook_test_node_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_taxonomy_term_create().
*/
function
entity_crud_hook_test_taxonomy_term_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_taxonomy_vocabulary_create().
*/
function
entity_crud_hook_test_taxonomy_vocabulary_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_user_create().
*/
function
entity_crud_hook_test_user_create
()
{
$_SESSION
[
'entity_crud_hook_test'
][]
=
(
__FUNCTION__
.
' called'
);
}
/**
* Implements hook_entity_presave().
*/
...
...
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