Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
linkchecker-3247797
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
linkchecker-3247797
Commits
0688517b
Commit
0688517b
authored
5 years ago
by
Thalles Ferreira
Committed by
Alexander Hass
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3059660
by thalles: Dependency injection on
LinkCheckerAdminSettingsForm
parent
b294ca0d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/LinkCheckerAdminSettingsForm.php
+47
-8
47 additions, 8 deletions
src/Form/LinkCheckerAdminSettingsForm.php
with
47 additions
and
8 deletions
src/Form/LinkCheckerAdminSettingsForm.php
+
47
−
8
View file @
0688517b
...
@@ -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
(
'p
lugin
.m
anager
.filter'
)
;
$manager
=
$this
->
filterP
lugin
M
anager
;
$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
.f
ormatter
'
)
,
$this
->
date
F
ormatter
,
'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
(
'
link
c
hecker
.checker'
)
->
queueLinks
(
TRUE
);
$this
->
link
C
hecker
Service
->
queueLinks
(
TRUE
);
}
}
$config
$config
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment