Commit 1b60e4a8 authored by Sutharsan's avatar Sutharsan Committed by Sutharsan

Issue #2965649 by Sutharsan, nkoporec: Dependency injection in FieldBlockConfigForm

parent 39a57c41
......@@ -2,8 +2,10 @@
namespace Drupal\fieldblock\Form;
use Drupal\Core\Block\BlockManager;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -37,6 +39,20 @@ class FieldBlockConfigForm extends ConfigFormBase {
*/
protected $fieldblockController;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The block manager.
*
* @var \Drupal\Core\Block\BlockManager
*/
protected $blockManager;
/**
* Constructs a \Drupal\fieldblock\Form\FieldBlockConfigForm object.
*
......@@ -46,12 +62,18 @@ class FieldBlockConfigForm extends ConfigFormBase {
* The entity type manager.
* @param \Drupal\fieldblock\BlockEntityStorage $storage
* The block entity storage.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler.
* @param \Drupal\Core\Block\BlockManager $blockManager
* The block manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entityTypeManager, BlockEntityStorage $storage) {
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entityTypeManager, BlockEntityStorage $storage, ModuleHandlerInterface $moduleHandler, BlockManager $blockManager) {
parent::__construct($config_factory);
$this->entityTypeManager = $entityTypeManager;
$this->storage = $storage;
$this->fieldblockController = new FieldBlockController();
$this->moduleHandler = $moduleHandler;
$this->blockManager = $blockManager;
}
/**
......@@ -61,7 +83,9 @@ class FieldBlockConfigForm extends ConfigFormBase {
return new static(
$container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('fieldblock.block_storage')
$container->get('fieldblock.block_storage'),
$container->get('module_handler'),
$container->get('plugin.manager.block')
);
}
......@@ -169,8 +193,8 @@ class FieldBlockConfigForm extends ConfigFormBase {
if ($clear_cache) {
// Invalidate the block cache to update fieldblock derivatives.
if (\Drupal::moduleHandler()->moduleExists('block')) {
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
if ($this->moduleHandler->moduleExists('block')) {
$this->blockManager->clearCachedDefinitions();
}
}
}
......
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