Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
9617c203
Commit
9617c203
authored
Sep 09, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2319171
by andypost, swentel | yched: Move entity_invoke_bundle_hook() to EntityManager.
parent
61215d04
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
74 deletions
+87
-74
core/includes/entity.inc
core/includes/entity.inc
+0
-38
core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
.../lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
+3
-3
core/lib/Drupal/Core/Entity/EntityManager.php
core/lib/Drupal/Core/Entity/EntityManager.php
+41
-11
core/lib/Drupal/Core/Entity/EntityManagerInterface.php
core/lib/Drupal/Core/Entity/EntityManagerInterface.php
+38
-0
core/lib/Drupal/Core/Extension/ModuleHandler.php
core/lib/Drupal/Core/Extension/ModuleHandler.php
+1
-1
core/modules/block_content/src/Entity/BlockContentType.php
core/modules/block_content/src/Entity/BlockContentType.php
+1
-18
core/modules/system/tests/modules/entity_test/entity_test.module
...dules/system/tests/modules/entity_test/entity_test.module
+3
-3
No files found.
core/includes/entity.inc
View file @
9617c203
...
@@ -43,44 +43,6 @@ function entity_get_bundles($entity_type = NULL) {
...
@@ -43,44 +43,6 @@ function entity_get_bundles($entity_type = NULL) {
}
}
}
}
/**
* Notifies modules about an operation that was performed on a entity bundle.
*
* @param string $hook
* One of 'create', 'rename' or 'delete'.
* @param string $entity_type
* The entity type to which the bundle is bound.
* @param string $bundle
* The name of the bundle on which the operation was performed.
* @param string|null $bundle_new
* The new name of the bundle in case of a 'rename' operation. Defaults to
* NULL.
*/
function
entity_invoke_bundle_hook
(
$hook
,
$entity_type
,
$bundle
,
$bundle_new
=
NULL
)
{
$entity_manager
=
\
Drupal
::
entityManager
();
$entity_manager
->
clearCachedBundles
();
// Notify the entity storage.
$method
=
'onBundle'
.
ucfirst
(
$hook
);
$storage
=
$entity_manager
->
getStorage
(
$entity_type
);
if
(
method_exists
(
$storage
,
$method
))
{
$storage
->
$method
(
$bundle
,
$bundle_new
);
}
// Notify the entity manager.
if
(
method_exists
(
$entity_manager
,
$method
))
{
$entity_manager
->
$method
(
$entity_type
,
$bundle
,
$bundle_new
);
}
// Invoke hook_entity_bundle_*() hooks.
\
Drupal
::
moduleHandler
()
->
invokeAll
(
'entity_bundle_'
.
$hook
,
array
(
$entity_type
,
$bundle
,
$bundle_new
));
// Clear the cached field definitions (not needed in case of 'create').
if
(
$hook
==
'rename'
||
$hook
==
'delete'
)
{
$entity_manager
->
clearCachedFieldDefinitions
();
}
}
/**
/**
* Loads an entity from the database.
* Loads an entity from the database.
*
*
...
...
core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
View file @
9617c203
...
@@ -68,11 +68,11 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
...
@@ -68,11 +68,11 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent
::
postSave
(
$storage
,
$update
);
parent
::
postSave
(
$storage
,
$update
);
if
(
!
$update
)
{
if
(
!
$update
)
{
entity_invoke_bundle_hook
(
'c
reate
'
,
$this
->
getEntityType
()
->
getBundleOf
(),
$this
->
id
());
$this
->
entityManager
()
->
onBundleC
reate
(
$this
->
getEntityType
()
->
getBundleOf
(),
$this
->
id
());
}
}
elseif
(
$this
->
getOriginalId
()
!=
$this
->
id
())
{
elseif
(
$this
->
getOriginalId
()
!=
$this
->
id
())
{
$this
->
renameDisplays
();
$this
->
renameDisplays
();
entity_invoke_bundle_hook
(
'r
ename
'
,
$this
->
getEntityType
()
->
getBundleOf
(),
$this
->
getOriginalId
(),
$this
->
id
());
$this
->
entityManager
()
->
onBundleR
ename
(
$this
->
getEntityType
()
->
getBundleOf
(),
$this
->
getOriginalId
(),
$this
->
id
());
}
}
}
}
...
@@ -84,7 +84,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
...
@@ -84,7 +84,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
foreach
(
$entities
as
$entity
)
{
foreach
(
$entities
as
$entity
)
{
$entity
->
deleteDisplays
();
$entity
->
deleteDisplays
();
entity_invoke_bundle_hook
(
'd
elete
'
,
$entity
->
getEntityType
()
->
getBundleOf
(),
$entity
->
id
());
\
Drupal
::
entityManager
()
->
onBundleD
elete
(
$entity
->
getEntityType
()
->
getBundleOf
(),
$entity
->
id
());
}
}
}
}
...
...
core/lib/Drupal/Core/Entity/EntityManager.php
View file @
9617c203
...
@@ -994,19 +994,30 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
...
@@ -994,19 +994,30 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
}
}
/**
/**
* Acts on entity bundle rename.
* {@inheritdoc}
*
*/
* @param string $entity_type_id
public
function
onBundleCreate
(
$entity_type_id
,
$bundle
)
{
* The entity type to which the bundle is bound.
$this
->
clearCachedBundles
();
* @param string $bundle_old
// Notify the entity storage.
* The previous name of the bundle.
$storage
=
$this
->
getStorage
(
$entity_type_id
);
* @param string $bundle_new
if
(
$storage
instanceof
FieldableEntityStorageInterface
)
{
* The new name of the bundle.
$storage
->
onBundleCreate
(
$bundle
);
*
}
* @see entity_invoke_bundle_hook()
// Invoke hook_entity_bundle_create() hook.
* @see entity_crud
$this
->
moduleHandler
->
invokeAll
(
'entity_bundle_create'
,
array
(
$entity_type_id
,
$bundle
));
}
/**
* {@inheritdoc}
*/
*/
public
function
onBundleRename
(
$entity_type_id
,
$bundle_old
,
$bundle_new
)
{
public
function
onBundleRename
(
$entity_type_id
,
$bundle_old
,
$bundle_new
)
{
$this
->
clearCachedBundles
();
// Notify the entity storage.
$storage
=
$this
->
getStorage
(
$entity_type_id
);
if
(
$storage
instanceof
FieldableEntityStorageInterface
)
{
$storage
->
onBundleRename
(
$bundle_old
,
$bundle_new
);
}
// Rename existing base field bundle overrides.
// Rename existing base field bundle overrides.
$overrides
=
$this
->
getStorage
(
'base_field_override'
)
->
loadByProperties
(
array
(
'entity_type'
=>
$entity_type_id
,
'bundle'
=>
$bundle_old
));
$overrides
=
$this
->
getStorage
(
'base_field_override'
)
->
loadByProperties
(
array
(
'entity_type'
=>
$entity_type_id
,
'bundle'
=>
$bundle_old
));
foreach
(
$overrides
as
$override
)
{
foreach
(
$overrides
as
$override
)
{
...
@@ -1015,6 +1026,25 @@ public function onBundleRename($entity_type_id, $bundle_old, $bundle_new) {
...
@@ -1015,6 +1026,25 @@ public function onBundleRename($entity_type_id, $bundle_old, $bundle_new) {
$override
->
allowBundleRename
();
$override
->
allowBundleRename
();
$override
->
save
();
$override
->
save
();
}
}
// Invoke hook_entity_bundle_rename() hook.
$this
->
moduleHandler
->
invokeAll
(
'entity_bundle_rename'
,
array
(
$entity_type_id
,
$bundle_old
,
$bundle_new
));
$this
->
clearCachedFieldDefinitions
();
}
/**
* {@inheritdoc}
*/
public
function
onBundleDelete
(
$entity_type_id
,
$bundle
)
{
$this
->
clearCachedBundles
();
// Notify the entity storage.
$storage
=
$this
->
getStorage
(
$entity_type_id
);
if
(
$storage
instanceof
FieldableEntityStorageInterface
)
{
$storage
->
onBundleDelete
(
$bundle
);
}
// Invoke hook_entity_bundle_delete() hook.
$this
->
moduleHandler
->
invokeAll
(
'entity_bundle_delete'
,
array
(
$entity_type_id
,
$bundle
));
$this
->
clearCachedFieldDefinitions
();
}
}
}
}
core/lib/Drupal/Core/Entity/EntityManagerInterface.php
View file @
9617c203
...
@@ -397,4 +397,42 @@ public function loadEntityByUuid($entity_type_id, $uuid);
...
@@ -397,4 +397,42 @@ public function loadEntityByUuid($entity_type_id, $uuid);
*/
*/
public
function
getEntityTypeFromClass
(
$class_name
);
public
function
getEntityTypeFromClass
(
$class_name
);
/**
* Reacts to the creation of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle
* The name of the bundle.
*
* @see entity_crud
*/
public
function
onBundleCreate
(
$entity_type_id
,
$bundle
);
/**
* Reacts to the rename of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle_old
* The previous name of the bundle.
* @param string $bundle_new
* The new name of the bundle.
*
* @see entity_crud
*/
public
function
onBundleRename
(
$entity_type_id
,
$bundle_old
,
$bundle_new
);
/**
* Reacts to the deletion of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle
* The bundle that was just deleted.
*
* @see entity_crud
*/
public
function
onBundleDelete
(
$entity_type_id
,
$bundle
);
}
}
core/lib/Drupal/Core/Extension/ModuleHandler.php
View file @
9617c203
...
@@ -944,7 +944,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
...
@@ -944,7 +944,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
foreach
(
$entity_manager
->
getDefinitions
()
as
$entity_type_id
=>
$entity_type
)
{
foreach
(
$entity_manager
->
getDefinitions
()
as
$entity_type_id
=>
$entity_type
)
{
if
(
$entity_type
->
getProvider
()
==
$module
)
{
if
(
$entity_type
->
getProvider
()
==
$module
)
{
foreach
(
array_keys
(
$entity_manager
->
getBundleInfo
(
$entity_type_id
))
as
$bundle
)
{
foreach
(
array_keys
(
$entity_manager
->
getBundleInfo
(
$entity_type_id
))
as
$bundle
)
{
entity_
invoke_bundle_hook
(
'd
elete
'
,
$entity_type_id
,
$bundle
);
$
entity_
manager
->
onBundleD
elete
(
$entity_type_id
,
$bundle
);
}
}
}
}
}
}
...
...
core/modules/block_content/src/Entity/BlockContentType.php
View file @
9617c203
...
@@ -77,24 +77,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
...
@@ -77,24 +77,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent
::
postSave
(
$storage
,
$update
);
parent
::
postSave
(
$storage
,
$update
);
if
(
!
$update
&&
!
$this
->
isSyncing
())
{
if
(
!
$update
&&
!
$this
->
isSyncing
())
{
entity_invoke_bundle_hook
(
'create'
,
'block_content'
,
$this
->
id
());
block_content_add_body_field
(
$this
->
id
);
if
(
!
$this
->
isSyncing
())
{
block_content_add_body_field
(
$this
->
id
);
}
}
elseif
(
$this
->
getOriginalId
()
!=
$this
->
id
)
{
entity_invoke_bundle_hook
(
'rename'
,
'block_content'
,
$this
->
getOriginalId
(),
$this
->
id
);
}
}
/**
* {@inheritdoc}
*/
public
static
function
postDelete
(
EntityStorageInterface
$storage
,
array
$entities
)
{
parent
::
postDelete
(
$storage
,
$entities
);
foreach
(
$entities
as
$entity
)
{
entity_invoke_bundle_hook
(
'delete'
,
'block_content'
,
$entity
->
id
());
}
}
}
}
...
...
core/modules/system/tests/modules/entity_test/entity_test.module
View file @
9617c203
...
@@ -104,7 +104,7 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity
...
@@ -104,7 +104,7 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity
$bundles
+=
array
(
$bundle
=>
array
(
'label'
=>
$text
?
$text
:
$bundle
));
$bundles
+=
array
(
$bundle
=>
array
(
'label'
=>
$text
?
$text
:
$bundle
));
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
entity_invoke_bundle_hook
(
'c
reate
'
,
$entity_type
,
$bundle
);
\
Drupal
::
entityManager
()
->
onBundleC
reate
(
$entity_type
,
$bundle
);
}
}
/**
/**
...
@@ -124,7 +124,7 @@ function entity_test_rename_bundle($bundle_old, $bundle_new, $entity_type = 'ent
...
@@ -124,7 +124,7 @@ function entity_test_rename_bundle($bundle_old, $bundle_new, $entity_type = 'ent
unset
(
$bundles
[
$bundle_old
]);
unset
(
$bundles
[
$bundle_old
]);
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
entity_invoke_bundle_hook
(
'r
ename
'
,
$entity_type
,
$bundle_old
,
$bundle_new
);
\
Drupal
::
entityManager
()
->
onBundleR
ename
(
$entity_type
,
$bundle_old
,
$bundle_new
);
}
}
/**
/**
...
@@ -141,7 +141,7 @@ function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
...
@@ -141,7 +141,7 @@ function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
unset
(
$bundles
[
$bundle
]);
unset
(
$bundles
[
$bundle
]);
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
\
Drupal
::
state
()
->
set
(
$entity_type
.
'.bundles'
,
$bundles
);
entity_invoke_bundle_hook
(
'd
elete
'
,
$entity_type
,
$bundle
);
\
Drupal
::
entityManager
()
->
onBundleD
elete
(
$entity_type
,
$bundle
);
}
}
/**
/**
...
...
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