Skip to content
Snippets Groups Projects
Commit e9ba1f2c authored by Arti's avatar Arti Committed by howard ge
Browse files

Issue #3370973 by arti_parmar: \Drupal calls should be avoided in classes, use...

Issue #3370973 by arti_parmar: \Drupal calls should be avoided in classes, use dependency injection instead
parent 697a4532
No related branches found
Tags 8.x-1.0-rc2
No related merge requests found
......@@ -13,6 +13,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides a base form for FieldValidationRule.
......@@ -47,6 +48,13 @@ abstract class FieldValidationRuleFormBase extends FormBase {
*/
protected $pluginCacheClearer;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new FieldValidationRuleForm.
*
......@@ -54,10 +62,13 @@ abstract class FieldValidationRuleFormBase extends FormBase {
* The entity field manager.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* The plugin cache clearer.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(EntityFieldManagerInterface $entity_field_manager, CachedDiscoveryClearerInterface $plugin_cache_clearer) {
public function __construct(EntityFieldManagerInterface $entity_field_manager, CachedDiscoveryClearerInterface $plugin_cache_clearer, ModuleHandlerInterface $module_handler) {
$this->entityFieldManager = $entity_field_manager;
$this->pluginCacheClearer = $plugin_cache_clearer;
$this->moduleHandler = $module_handler;
}
/**
......@@ -66,7 +77,8 @@ abstract class FieldValidationRuleFormBase extends FormBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_field.manager'),
$container->get('plugin.cache_clearer')
$container->get('plugin.cache_clearer'),
$container->get('module_handler')
);
}
......@@ -191,7 +203,7 @@ abstract class FieldValidationRuleFormBase extends FormBase {
];
$form['data']['#tree'] = TRUE;
// Add a token link.
if (\Drupal::moduleHandler()->moduleExists('token')) {
if ($this->moduleHandler->moduleExists('token')) {
//Some entity not use entity_type_id as token type, we need change it.
switch ($entity_type_id) {
case 'taxonomy_term':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment