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
context
Commits
ee5502e8
Commit
ee5502e8
authored
Mar 20, 2018
by
git
Committed by
boshtian
Mar 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2948331
by nkoporec, icurk: Use dependency injection in Blocks and ContextBlockPageVariant
parent
ed67e4c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
src/Plugin/ContextReaction/Blocks.php
src/Plugin/ContextReaction/Blocks.php
+12
-4
src/Plugin/DisplayVariant/ContextBlockPageVariant.php
src/Plugin/DisplayVariant/ContextBlockPageVariant.php
+13
-4
No files found.
src/Plugin/ContextReaction/Blocks.php
View file @
ee5502e8
...
...
@@ -6,6 +6,7 @@ use Drupal\Core\Session\AccountInterface;
use
Drupal\Core\Url
;
use
Drupal\Core\Form\FormState
;
use
Drupal\Core\Render\Element
;
use
Drupal\Core\Block\BlockManager
;
use
Drupal\context\ContextInterface
;
use
Drupal\context\Form\AjaxFormTrait
;
use
Drupal\Core\Form\FormStateInterface
;
...
...
@@ -83,6 +84,11 @@ class Blocks extends ContextReactionPluginBase implements ContainerFactoryPlugin
*/
protected
$account
;
/**
* @var BlockManager
*/
protected
$blockManager
;
/**
* {@inheritdoc}
*/
...
...
@@ -95,7 +101,8 @@ class Blocks extends ContextReactionPluginBase implements ContainerFactoryPlugin
ThemeHandlerInterface
$themeHandler
,
ContextRepositoryInterface
$contextRepository
,
ContextHandlerInterface
$contextHandler
,
AccountInterface
$account
AccountInterface
$account
,
BlockManager
$blockManager
)
{
parent
::
__construct
(
$configuration
,
$pluginId
,
$pluginDefinition
);
...
...
@@ -105,6 +112,7 @@ class Blocks extends ContextReactionPluginBase implements ContainerFactoryPlugin
$this
->
contextRepository
=
$contextRepository
;
$this
->
contextHandler
=
$contextHandler
;
$this
->
account
=
$account
;
$this
->
blockManager
=
$blockManager
;
}
/**
...
...
@@ -120,7 +128,8 @@ class Blocks extends ContextReactionPluginBase implements ContainerFactoryPlugin
$container
->
get
(
'theme_handler'
),
$container
->
get
(
'context.repository'
),
$container
->
get
(
'context.handler'
),
$container
->
get
(
'current_user'
)
$container
->
get
(
'current_user'
),
$container
->
get
(
'plugin.manager.block'
)
);
}
...
...
@@ -340,8 +349,7 @@ class Blocks extends ContextReactionPluginBase implements ContainerFactoryPlugin
*/
public
function
getBlocks
()
{
if
(
!
$this
->
blocksCollection
)
{
$blockManager
=
\
Drupal
::
service
(
'plugin.manager.block'
);
$this
->
blocksCollection
=
new
BlockCollection
(
$blockManager
,
$this
->
blocks
);
$this
->
blocksCollection
=
new
BlockCollection
(
$this
->
blockManager
,
$this
->
blocks
);
}
return
$this
->
blocksCollection
;
...
...
src/Plugin/DisplayVariant/ContextBlockPageVariant.php
View file @
ee5502e8
...
...
@@ -42,6 +42,11 @@ class ContextBlockPageVariant extends VariantBase implements PageVariantInterfac
*/
protected
$title
=
''
;
/**
* @var VariantManager
*/
protected
$displayVariant
;
/**
* Constructs a new ContextBlockPageVariant.
*
...
...
@@ -56,10 +61,14 @@ class ContextBlockPageVariant extends VariantBase implements PageVariantInterfac
*
* @param ContextManager $contextManager
* The context module manager.
*
* @param VariantManager $displayVariant
* The variant manager.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
ContextManager
$contextManager
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
ContextManager
$contextManager
,
VariantManager
$displayVariant
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
contextManager
=
$contextManager
;
$this
->
displayVariant
=
$displayVariant
;
}
/**
...
...
@@ -70,7 +79,8 @@ class ContextBlockPageVariant extends VariantBase implements PageVariantInterfac
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'context.manager'
)
$container
->
get
(
'context.manager'
),
$container
->
get
(
'plugin.manager.display_variant'
)
);
}
...
...
@@ -123,8 +133,7 @@ class ContextBlockPageVariant extends VariantBase implements PageVariantInterfac
* Get build from Block layout.
*/
private
function
getBuildFromBlockLayout
()
{
$plugin_manager
=
\
Drupal
::
service
(
'plugin.manager.display_variant'
);
$display_variant
=
$plugin_manager
->
createInstance
(
'block_page'
,
$plugin_manager
->
getDefinition
(
'block_page'
));
$display_variant
=
$this
->
displayVariant
->
createInstance
(
'block_page'
,
$this
->
displayVariant
->
getDefinition
(
'block_page'
));
$display_variant
->
setTitle
(
$this
->
title
);
return
$display_variant
->
build
();
...
...
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