Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
74eb2b9b
Commit
74eb2b9b
authored
Nov 12, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2371725
by dawehner: Fixed Don't use theme negotiation all over the place.
parent
08d3ebba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
43 deletions
+23
-43
core/core.services.yml
core/core.services.yml
+1
-1
core/lib/Drupal/Core/Cache/ThemeCacheContext.php
core/lib/Drupal/Core/Cache/ThemeCacheContext.php
+9
-19
core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
...les/system/src/Plugin/Condition/CurrentThemeCondition.php
+11
-23
core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php
.../system/src/Tests/Condition/CurrentThemeConditionTest.php
+2
-0
No files found.
core/core.services.yml
View file @
74eb2b9b
...
...
@@ -25,7 +25,7 @@ services:
-
{
name
:
cache.context
}
cache_context.theme
:
class
:
Drupal\Core\Cache\ThemeCacheContext
arguments
:
[
'
@
current_route_match'
,
'
@theme.negotiato
r'
]
arguments
:
[
'
@
theme.manage
r'
]
tags
:
-
{
name
:
cache.context
}
cache_context.timezone
:
...
...
core/lib/Drupal/Core/Cache/ThemeCacheContext.php
View file @
74eb2b9b
...
...
@@ -8,7 +8,7 @@
namespace
Drupal\Core\Cache
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\Theme\Theme
Negotiato
rInterface
;
use
Drupal\Core\Theme\Theme
Manage
rInterface
;
/**
* Defines the ThemeCacheContext service, for "per theme" caching.
...
...
@@ -16,30 +16,20 @@
class
ThemeCacheContext
implements
CacheContextInterface
{
/**
* The
current route match
.
* The
theme manager
.
*
* @var \Drupal\Core\
Routing\RouteMatch
* @var \Drupal\Core\
Theme\ThemeManagerInterface
*/
protected
$routeMatch
;
/**
* The theme negotiator.
*
* @var \Drupal\Core\Theme\ThemeNegotiator
*/
protected
$themeNegotiator
;
protected
$themeManager
;
/**
* Constructs a new ThemeCacheContext service.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Theme\ThemeNegotiatorInterface $theme_negotiator
* The theme negotiator.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public
function
__construct
(
RouteMatchInterface
$route_match
,
ThemeNegotiatorInterface
$theme_negotiator
)
{
$this
->
routeMatch
=
$route_match
;
$this
->
themeNegotiator
=
$theme_negotiator
;
public
function
__construct
(
ThemeManagerInterface
$theme_manager
)
{
$this
->
themeManager
=
$theme_manager
;
}
/**
...
...
@@ -53,7 +43,7 @@ public static function getLabel() {
* {@inheritdoc}
*/
public
function
getContext
()
{
return
$this
->
theme
Negotiato
r
->
d
et
ermine
ActiveTheme
(
$this
->
routeMatch
)
?:
'stark'
;
return
$this
->
theme
Manage
r
->
g
etActiveTheme
(
)
->
getName
(
)
?:
'stark'
;
}
}
core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
View file @
74eb2b9b
...
...
@@ -11,8 +11,7 @@
use
Drupal\Core\Extension\ThemeHandlerInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\Theme\ThemeNegotiatorInterface
;
use
Drupal\Core\Theme\ThemeManagerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
...
...
@@ -26,11 +25,11 @@
class
CurrentThemeCondition
extends
ConditionPluginBase
implements
ContainerFactoryPluginInterface
{
/**
* The theme
negotiato
r.
* The theme
manage
r.
*
* @var \Drupal\Core\Theme\Theme
Negotiato
rInterface
* @var \Drupal\Core\Theme\Theme
Manage
rInterface
*/
protected
$theme
Negotiato
r
;
protected
$theme
Manage
r
;
/**
* The theme handler.
...
...
@@ -39,13 +38,6 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
*/
protected
$themeHandler
;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected
$routeMatch
;
/**
* Constructs a CurrentThemeCondition condition plugin.
*
...
...
@@ -55,18 +47,15 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Theme\Theme
Negotiato
rInterface $theme_
negotiato
r
* The theme
negotiato
r.
* @param \Drupal\Core\Theme\Theme
Manage
rInterface $theme_
manage
r
* The theme
manage
r.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
Theme
Negotiato
rInterface
$theme_
negotiato
r
,
ThemeHandlerInterface
$theme_handler
,
RouteMatchInterface
$route_match
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
Theme
Manage
rInterface
$theme_
manage
r
,
ThemeHandlerInterface
$theme_handler
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
theme
Negotiato
r
=
$theme_
negotiato
r
;
$this
->
theme
Manage
r
=
$theme_
manage
r
;
$this
->
themeHandler
=
$theme_handler
;
$this
->
routeMatch
=
$route_match
;
}
/**
...
...
@@ -77,9 +66,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'theme.negotiator'
),
$container
->
get
(
'theme_handler'
),
$container
->
get
(
'current_route_match'
)
$container
->
get
(
'theme.manager'
),
$container
->
get
(
'theme_handler'
)
);
}
...
...
@@ -121,7 +109,7 @@ public function evaluate() {
return
TRUE
;
}
return
$this
->
theme
Negotiato
r
->
d
et
ermine
ActiveTheme
(
$this
->
routeMatch
)
==
$this
->
configuration
[
'theme'
];
return
$this
->
theme
Manage
r
->
g
etActiveTheme
(
)
->
getName
(
)
==
$this
->
configuration
[
'theme'
];
}
/**
...
...
core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php
View file @
74eb2b9b
...
...
@@ -45,6 +45,8 @@ public function testCurrentTheme() {
// Set the expected theme to be used.
\
Drupal
::
config
(
'system.theme'
)
->
set
(
'default'
,
'test_theme'
)
->
save
();
\
Drupal
::
theme
()
->
resetActiveTheme
();
$this
->
assertTrue
(
$condition
->
execute
());
$this
->
assertFalse
(
$condition_negated
->
execute
());
}
...
...
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