Commit ee5502e8 authored by git's avatar git Committed by boshtian

Issue #2948331 by nkoporec, icurk: Use dependency injection in Blocks and ContextBlockPageVariant

parent ed67e4c0
......@@ -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;
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment