Skip to content
Snippets Groups Projects
Commit 1edab0ad authored by Eli's avatar Eli Committed by Fran Garcia-Linares
Browse files

Resolve #3184476 "Domain flag"

parent df8b2d2f
Branches
Tags 8.x-1.5
1 merge request!1Resolve #3184476 "Domain flag"
......@@ -164,6 +164,31 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
],
];
$form['add_host'] = [
'#type' => 'checkbox',
'#title' => $this->t('Send host information'),
'#description' => $this->t("Adds host information into notifications."),
'#default_value' => $config->get('add_host'),
];
$host = \Drupal::request()->getSchemeAndHttpHost();
$form['custom_host_value'] = [
'#type' => 'textfield',
'#title' => $this->t('Custom host value'),
'#description' => $this->t('Add a custom value to be sent with notifications. Leave empty for %current (current host)', ['%current' => $host]),
'#default_value' => $config->get('custom_host_value'),
'#attributes' => [
'placeholder' => $host,
],
'#states' => [
'visible' => [
':checkbox[name="add_host"]' => [
'checked' => TRUE,
],
],
],
];
$form['notification_types'] = [
'#markup' => '<hr /><h3>' . $this->t('Notification types') . '</h3>',
];
......@@ -193,7 +218,7 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
];
if ($this->moduleHandler->moduleExists('slack')) {
$is_slack_configured = \Drupal::config('slack.settings')->get('slack_webhook_url') ?: NULL;
$is_slack_configured = \Drupal::config('slack.settings')->get('slack_webhook_url') ?: NULL;
$form['slack'] = [
'#type' => 'checkbox',
'#title' => $this->t('Slack notification'),
......@@ -206,12 +231,8 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
if (!$is_slack_configured) {
$url = Url::fromRoute('slack.admin_settings');
$link = Link::fromTextAndUrl('here', $url)->toString();
$form['slack_message'] = [
'#markup' => '<p>' .
$this->t('NOTICE: While Slack module is enabled, it is not properly configured. Please configure Slack ')
. $link
. '</p>',
'#markup' => '<p>' . $this->t('NOTICE: While Slack module is enabled, it is not properly configured. Please <a href="@configure-slack">configure Slack</a>.', ['@configure-slack' => $url->toString()]) . '</p>',
];
}
}
......@@ -300,6 +321,8 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
$slack = $form_state->getValue('slack');
$list_changes = $form_state->getValue('list_changes');
$list_changes_limit = $form_state->getValue('list_changes_limit');
$add_host = $form_state->getValue('add_host');
$custom_host_value = $form_state->getValue('custom_host_value');
$this->config('config_notify.settings')
->set('cron', $cron)
......@@ -309,6 +332,8 @@ class ConfigNotifySettingsForm extends ConfigFormBase {
->set('email_to', $email_to)
->set('list_changes', $list_changes)
->set('list_changes_limit', $list_changes_limit)
->set('add_host', $add_host)
->set('custom_host_value', $custom_host_value)
->save();
}
......
......@@ -187,13 +187,22 @@ class NotifierService {
* The default message
*/
public function getDefaultMessage($markdown = FALSE) {
$bold = ($markdown) ? '*' : '';
$wrapping = ($markdown) ? '```' : '';
$wrapping_single = ($markdown) ? '`' : '';
$message = "";
$changes = $this->getChanges();
$list_changes = $this->configFactory->get('config_notify.settings')->get('list_changes');
$host = $this->getHostInformation();
if ($host) {
$message .= $wrapping_single . $host . "$wrapping_single\n\n";
}
$message .= $this->t("There are configuration changes not exported on the site.");
$message = $this->t("There are configuration changes not exported on the site.");
if ($list_changes && $changes !== "") {
$bold = ($markdown) ? '*' : '';
$wrapping = ($markdown) ? '```' : '';
$message .= "\n\n$bold" . $this->t("Config changes:") . "$bold\n\n";
$message .= $wrapping . $changes . $wrapping;
}
......@@ -221,6 +230,22 @@ class NotifierService {
$this->state->set('config_notify.last_sent', $time);
}
/**
* Returns host information.
*
* @return mixed
* String or false.
*/
private function getHostInformation() {
$add_host = $this->configFactory->get('config_notify.settings')->get('add_host');
$custom_host_value = trim($this->configFactory->get('config_notify.settings')->get('custom_host_value'));
if ($add_host) {
$current_host = \Drupal::request()->getSchemeAndHttpHost();
return $custom_host_value !== "" ? $custom_host_value : $current_host;
}
return FALSE;
}
/**
* Sends slack notification.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment