Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
config_notify
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
config_notify
Commits
9e3ed85d
Commit
9e3ed85d
authored
5 years ago
by
Fran Garcia-Linares
Browse files
Options
Downloads
Patches
Plain Diff
Inject services.
parent
965ace5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/ConfigNotifySettingsForm.php
+46
-12
46 additions, 12 deletions
src/Form/ConfigNotifySettingsForm.php
with
46 additions
and
12 deletions
src/Form/ConfigNotifySettingsForm.php
+
46
−
12
View file @
9e3ed85d
...
...
@@ -8,6 +8,9 @@ use Drupal\Core\Url;
use
Drupal\Core\Link
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\config_notify
\NotifierService
;
use
Drupal\Core\Messenger\MessengerInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Datetime\DateFormatterInterface
;
/**
* Settings form for config_notify.
...
...
@@ -21,14 +24,44 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
*/
protected
$notifier
;
/**
* Drupal\Core\Messenger\MessengerInterface definition.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected
$messenger
;
/**
* Drupal\Core\Extension\ModuleHandlerInterface definition.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* Drupal\Core\Datetime\DateFormatterInterface definition.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected
$dateFormatter
;
/**
* Constructs the object.
*
* @param \Drupal\config_notify\NotifierService $notifier
* The notifier service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
*/
public
function
__construct
(
NotifierService
$notifier
)
{
public
function
__construct
(
NotifierService
$notifier
,
MessengerInterface
$messenger
,
ModuleHandlerInterface
$module_handler
,
DateFormatterInterface
$date_formatter
)
{
$this
->
notifier
=
$notifier
;
$this
->
messenger
=
$messenger
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
dateFormatter
=
$date_formatter
;
}
/**
...
...
@@ -36,7 +69,10 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'config_notify.notifier'
)
$container
->
get
(
'config_notify.notifier'
),
$container
->
get
(
'messenger'
),
$container
->
get
(
'module_handler'
),
$container
->
get
(
'date.formatter'
)
);
}
...
...
@@ -61,16 +97,15 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$config
=
$this
->
config
(
'config_notify.settings'
);
$messenger
=
\Drupal
::
messenger
();
$changes
=
$this
->
notifier
->
checkChanges
();
if
(
$changes
)
{
$message
=
$this
->
t
(
'There are configuration changes.'
);
$messenger
->
addMessage
(
$message
,
'warning'
);
$
this
->
messenger
->
addMessage
(
$message
,
'warning'
);
}
else
{
$message
=
$this
->
t
(
'There are no configuration changes.'
);
$messenger
->
addMessage
(
$message
,
'status'
);
$
this
->
messenger
->
addMessage
(
$message
,
'status'
);
}
$form
[
'notification_frequency'
]
=
[
...
...
@@ -93,7 +128,7 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
$last_sent
=
$this
->
notifier
->
getLastNotificationSent
();
if
(
$last_sent
)
{
$date
=
\Drupal
::
service
(
'
date
.f
ormatter
'
)
->
format
(
$last_sent
);
$date
=
$this
->
date
F
ormatter
->
format
(
$last_sent
);
$form
[
'message'
]
=
[
'#markup'
=>
'<p>'
.
'<strong>'
.
$this
->
t
(
'Last notification was sent:'
)
.
'</strong> '
.
$date
.
'</p>'
,
];
...
...
@@ -110,8 +145,7 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
'#default_value'
=>
$config
->
get
(
'email'
),
];
$moduleHandler
=
\Drupal
::
service
(
'module_handler'
);
if
(
$moduleHandler
->
moduleExists
(
'slack'
))
{
if
(
$this
->
moduleHandler
->
moduleExists
(
'slack'
))
{
$form
[
'slack'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Slack notification'
),
...
...
@@ -173,19 +207,19 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
$config
=
$this
->
config
(
'config_notify.settings'
);
if
(
$config
->
get
(
'slack'
))
{
if
(
$this
->
notifier
->
notifySlack
(
$message
))
{
\Drupal
::
messenger
()
->
addMessage
(
$this
->
t
(
'Slack: Message was successfully sent.'
));
$this
->
messenger
->
addMessage
(
$this
->
t
(
'Slack: Message was successfully sent.'
));
}
else
{
\Drupal
::
messenger
()
->
addMessage
(
$this
->
t
(
'Slack: Message not sent. Please check log messages for details'
),
'warning'
);
$this
->
messenger
->
addMessage
(
$this
->
t
(
'Slack: Message not sent. Please check log messages for details'
),
'warning'
);
}
}
if
(
$config
->
get
(
'email'
))
{
if
(
$this
->
notifier
->
notifyEmail
(
$message
))
{
\Drupal
::
messenger
()
->
addMessage
(
$this
->
t
(
'Email: Message was successfully sent.'
));
$this
->
messenger
->
addMessage
(
$this
->
t
(
'Email: Message was successfully sent.'
));
}
else
{
\Drupal
::
messenger
()
->
addMessage
(
$this
->
t
(
'Email: Message not sent. Please check log messages for details'
),
'warning'
);
$this
->
messenger
->
addMessage
(
$this
->
t
(
'Email: Message not sent. Please check log messages for details'
),
'warning'
);
}
}
...
...
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