Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
9d276ca5
Commit
9d276ca5
authored
Jan 29, 2013
by
Nathaniel Catchpole
Browse files
Issue
#1892462
by tim.plunkett: EntityManager should use the CacheDecorator.
parent
8c1caeda
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/includes/common.inc
View file @
9d276ca5
...
...
@@ -6430,7 +6430,8 @@ function drupal_flush_all_caches() {
drupal_static_reset
();
// Clear all non-drupal_static() static caches.
// None currently; kept if any static caches need to be reset in the future.
// @todo Rebuild the kernel/container.
drupal_container
()
->
get
(
'plugin.manager.entity'
)
->
clearCachedDefinitions
();
// Rebuild module and theme data.
system_rebuild_module_data
();
...
...
core/includes/entity.inc
View file @
9d276ca5
...
...
@@ -23,24 +23,15 @@
*
* @see \Drupal\Core\Entity\EntityManager
* @see hook_entity_info_alter()
*
* @deprecated Use \Drupal\Core\Entity\EntityManager::getDefinitions() directly.
*/
function
entity_get_info
(
$entity_type
=
NULL
)
{
// Use the advanced drupal_static() pattern, since this is called very often.
static
$drupal_static_fast
;
if
(
!
isset
(
$drupal_static_fast
))
{
$drupal_static_fast
[
'entity_info'
]
=
&
drupal_static
(
__FUNCTION__
);
}
$entity_info
=
&
$drupal_static_fast
[
'entity_info'
];
if
(
empty
(
$entity_info
))
{
$entity_info
=
drupal_container
()
->
get
(
'plugin.manager.entity'
)
->
getDefinitions
();
}
if
(
empty
(
$entity_type
))
{
return
$entity_info
;
return
drupal_container
()
->
get
(
'plugin.manager.entity'
)
->
getDefinitions
()
;
}
else
if
(
isset
(
$entity_info
[
$entity_type
]))
{
return
$entity_info
[
$entity_type
]
;
else
{
return
drupal_container
()
->
get
(
'plugin.manager.entity'
)
->
getDefinition
(
$entity_type
)
;
}
}
...
...
@@ -48,11 +39,10 @@ function entity_get_info($entity_type = NULL) {
* Resets the cached information about entity types.
*/
function
entity_info_cache_clear
()
{
drupal_static_reset
(
'entity_get_info'
);
drupal_static_reset
(
'entity_get_view_modes'
);
drupal_static_reset
(
'entity_get_bundles'
);
// Clear all languages.
cache
()
->
deleteTags
(
array
(
'entity_info'
=>
TRUE
)
);
drupal_container
()
->
get
(
'plugin.manager.entity'
)
->
clearCachedDefinitions
(
);
}
/**
...
...
core/lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php
View file @
9d276ca5
...
...
@@ -13,7 +13,7 @@
interface
CachedDiscoveryInterface
extends
DiscoveryInterface
{
/**
* Clears
cached
plugin definitions.
* Clears
static and persistent
plugin definition
cache
s.
*/
public
function
clearCachedDefinitions
();
...
...
core/lib/Drupal/Core/Entity/EntityManager.php
View file @
9d276ca5
...
...
@@ -11,6 +11,7 @@
use
Drupal\Component\Plugin\Factory\DefaultFactory
;
use
Drupal\Component\Plugin\Discovery\ProcessDecorator
;
use
Drupal\Core\Plugin\Discovery\AlterDecorator
;
use
Drupal\Core\Plugin\Discovery\CacheDecorator
;
use
Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery
;
use
Drupal\Core\Plugin\Discovery\InfoHookDecorator
;
use
Drupal\Core\Cache\CacheBackendInterface
;
...
...
@@ -129,34 +130,6 @@
*/
class
EntityManager
extends
PluginManagerBase
{
/**
* The cache bin used for entity plugin definitions.
*
* @var string
*/
protected
$cacheBin
=
'cache'
;
/**
* The cache key used for entity plugin definitions.
*
* @var string
*/
protected
$cacheKey
=
'entity_info'
;
/**
* The cache expiration for entity plugin definitions.
*
* @var int
*/
protected
$cacheExpire
=
CacheBackendInterface
::
CACHE_PERMANENT
;
/**
* The cache tags used for entity plugin definitions.
*
* @var array
*/
protected
$cacheTags
=
array
(
'entity_info'
=>
TRUE
);
/**
* Contains instantiated controllers keyed by controller type and entity type.
*
...
...
@@ -197,36 +170,9 @@ public function __construct() {
$this
->
discovery
=
new
InfoHookDecorator
(
$this
->
discovery
,
'entity_info'
);
$this
->
discovery
=
new
ProcessDecorator
(
$this
->
discovery
,
array
(
$this
,
'processDefinition'
));
$this
->
discovery
=
new
AlterDecorator
(
$this
->
discovery
,
'entity_info'
);
$this
->
facto
ry
=
new
DefaultFactory
(
$this
);
$this
->
discove
ry
=
new
CacheDecorator
(
$this
->
discovery
,
'entity_info:'
.
language
(
LANGUAGE_TYPE_INTERFACE
)
->
langcode
,
'cache'
,
CacheBackendInterface
::
CACHE_PERMANENT
,
array
(
'entity_info'
=>
TRUE
)
);
// Entity type plugins includes translated strings, so each language is
// cached separately.
$this
->
cacheKey
.
=
':'
.
language
(
LANGUAGE_TYPE_INTERFACE
)
->
langcode
;
}
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinition().
*/
public
function
getDefinition
(
$plugin_id
)
{
$definitions
=
$this
->
getDefinitions
();
return
isset
(
$definitions
[
$plugin_id
])
?
$definitions
[
$plugin_id
]
:
NULL
;
}
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinitions().
*/
public
function
getDefinitions
()
{
// Because \Drupal\Core\Plugin\Discovery\CacheDecorator runs before
// definitions are processed and does not support cache tags, we perform our
// own caching.
if
(
$cache
=
cache
(
$this
->
cacheBin
)
->
get
(
$this
->
cacheKey
))
{
return
$cache
->
data
;
}
else
{
$definitions
=
parent
::
getDefinitions
();
cache
(
$this
->
cacheBin
)
->
set
(
$this
->
cacheKey
,
$definitions
,
$this
->
cacheExpire
,
$this
->
cacheTags
);
return
$definitions
;
}
$this
->
factory
=
new
DefaultFactory
(
$this
->
discovery
);
}
/**
...
...
core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php
View file @
9d276ca5
...
...
@@ -115,7 +115,7 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) {
$this
->
drupalPost
(
'admin/config/regional/content-language'
,
$edit
,
t
(
'Save'
));
$args
=
array
(
'@entity_type'
=>
$entity_type
,
'@bundle'
=>
$bundle
,
'@enabled'
=>
$enabled
?
'enabled'
:
'disabled'
);
$message
=
format_string
(
'Translation for entity @entity_type (@bundle) is @enabled.'
,
$args
);
drupal_static_reset
();
entity_info_cache_clear
();
return
$this
->
assertEqual
(
translation_entity_enabled
(
$entity_type
,
$bundle
),
$enabled
,
$message
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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