Skip to content
Snippets Groups Projects
Commit 0688517b authored by Thalles Ferreira's avatar Thalles Ferreira Committed by Alexander Hass
Browse files

Issue #3059660 by thalles: Dependency injection on

LinkCheckerAdminSettingsForm
parent b294ca0d
No related branches found
No related tags found
No related merge requests found
...@@ -3,15 +3,18 @@ ...@@ -3,15 +3,18 @@
namespace Drupal\linkchecker\Form; namespace Drupal\linkchecker\Form;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\filter\FilterPluginCollection; use Drupal\filter\FilterPluginCollection;
use Drupal\filter\FilterPluginManager;
use Drupal\linkchecker\LinkCheckerLinkInterface; use Drupal\linkchecker\LinkCheckerLinkInterface;
use Drupal\linkchecker\LinkCheckerService;
use Drupal\linkchecker\LinkCleanUp; use Drupal\linkchecker\LinkCleanUp;
use Drupal\linkchecker\LinkExtractorBatch; use Drupal\linkchecker\LinkExtractorBatch;
use Drupal\user\Entity\User; use Drupal\user\UserStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -19,6 +22,27 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -19,6 +22,27 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
class LinkCheckerAdminSettingsForm extends ConfigFormBase { class LinkCheckerAdminSettingsForm extends ConfigFormBase {
/**
* The service handle various date.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Manages text processing filters.
*
* @var \Drupal\filter\FilterPluginManager
*/
protected $filterPluginManager;
/**
* The service LinkChecker.
*
* @var \Drupal\linkchecker\LinkCheckerService
*/
protected $linkCheckerService;
/** /**
* The extractor batch. * The extractor batch.
* *
...@@ -33,13 +57,24 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -33,13 +57,24 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
*/ */
protected $linkCleanUp; protected $linkCleanUp;
/**
* The controller class for users..
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/** /**
* LinkCheckerAdminSettingsForm constructor. * LinkCheckerAdminSettingsForm constructor.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, LinkExtractorBatch $extractorBatch, LinkCleanUp $linkCleanUp) { public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter, FilterPluginManager $plugin_manager_filter, LinkCheckerService $linkchecker_checker, LinkExtractorBatch $extractorBatch, LinkCleanUp $linkCleanUp, UserStorageInterface $user_storage) {
parent::__construct($config_factory); parent::__construct($config_factory);
$this->dateFormatter = $date_formatter;
$this->extractorBatch = $extractorBatch; $this->extractorBatch = $extractorBatch;
$this->linkCleanUp = $linkCleanUp; $this->linkCleanUp = $linkCleanUp;
$this->linkCheckerService = $linkchecker_checker;
$this->filterPluginManager = $plugin_manager_filter;
$this->userStorage = $user_storage;
} }
/** /**
...@@ -48,8 +83,12 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -48,8 +83,12 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('config.factory'), $container->get('config.factory'),
$container->get('date.formatter'),
$container->get('plugin.manager.filter'),
$container->get('linkchecker.checker'),
$container->get('linkchecker.extractor_batch'), $container->get('linkchecker.extractor_batch'),
$container->get('linkchecker.clean_up') $container->get('linkchecker.clean_up'),
$container->get('entity_type.manager')->getStorage('user')
); );
} }
...@@ -184,7 +223,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -184,7 +223,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
]; ];
// Get all filters available on the system. // Get all filters available on the system.
$manager = \Drupal::service('plugin.manager.filter'); $manager = $this->filterPluginManager;
$bag = new FilterPluginCollection($manager, []); $bag = new FilterPluginCollection($manager, []);
$filter_info = $bag->getAll(); $filter_info = $bag->getAll();
$filter_options = []; $filter_options = [];
...@@ -265,7 +304,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -265,7 +304,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
7776000, 7776000,
]; ];
$period = array_map([ $period = array_map([
\Drupal::service('date.formatter'), $this->dateFormatter,
'formatInterval', 'formatInterval',
], array_combine($intervals, $intervals)); ], array_combine($intervals, $intervals));
$form['check']['linkchecker_check_interval'] = [ $form['check']['linkchecker_check_interval'] = [
...@@ -301,7 +340,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -301,7 +340,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
'#description' => $this->t('Defines error handling and custom actions to be executed if specific HTTP requests are failing.'), '#description' => $this->t('Defines error handling and custom actions to be executed if specific HTTP requests are failing.'),
'#open' => TRUE, '#open' => TRUE,
]; ];
$linkchecker_default_impersonate_account = User::load(1); $linkchecker_default_impersonate_account = $this->userStorage->load(1);
$form['error']['linkchecker_impersonate_account'] = [ $form['error']['linkchecker_impersonate_account'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('Impersonate user account'), '#title' => $this->t('Impersonate user account'),
...@@ -399,7 +438,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -399,7 +438,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
// Validate impersonation user name. // Validate impersonation user name.
$linkchecker_impersonate_account = user_load_by_name($form_state->getValue('linkchecker_impersonate_account')); $linkchecker_impersonate_account = user_load_by_name($form_state->getValue('linkchecker_impersonate_account'));
// @TODO: Cleanup // @TODO: Cleanup
// if (empty($linkchecker_impersonate_account->id())) { // if (empty($linkchecker_impersonate_account->id())) {
if ($linkchecker_impersonate_account && empty($linkchecker_impersonate_account->id())) { if ($linkchecker_impersonate_account && empty($linkchecker_impersonate_account->id())) {
$form_state->setErrorByName('linkchecker_impersonate_account', $this->t('User account %name cannot found.', ['%name' => $form_state->getValue('linkchecker_impersonate_account')])); $form_state->setErrorByName('linkchecker_impersonate_account', $this->t('User account %name cannot found.', ['%name' => $form_state->getValue('linkchecker_impersonate_account')]));
} }
...@@ -413,7 +452,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase { ...@@ -413,7 +452,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
// @todo: Move it to setting save hook. // @todo: Move it to setting save hook.
if ((int) $config->get('check.connections_max') != (int) $form_state->getValue('linkchecker_check_connections_max')) { if ((int) $config->get('check.connections_max') != (int) $form_state->getValue('linkchecker_check_connections_max')) {
\Drupal::service('linkchecker.checker')->queueLinks(TRUE); $this->linkCheckerService->queueLinks(TRUE);
} }
$config $config
......
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