Skip to content
Snippets Groups Projects
Commit 2ebe22b2 authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3275335 by AdamPS: Inform the admin if config import is needed

parent dab25e9f
Branches
Tags
No related merge requests found
......@@ -63,10 +63,6 @@ class TestEmailForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#tree'] = TRUE;
$form['description'] = [
'#markup' => '<p>' . $this->t('This page allows you to send a test email to a recipient of your choice.') . '</p>',
];
$form['recipient'] = [
'#title' => $this->t('Recipient'),
'#type' => 'textfield',
......
......@@ -115,6 +115,21 @@ class EmailBuilderManager extends DefaultPluginManager implements EmailBuilderMa
return $info ?? [];
}
/**
* {@inheritdoc}
*/
public function importRequired() {
$state_all = $this->keyValue->get('import', []);
foreach ($this->getDefinitions() as $id => $definition) {
if ($definition['import'] && (($state_all[$id] ?? self::IMPORT_READY) == self::IMPORT_READY)) {
return TRUE;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
......
......@@ -36,6 +36,14 @@ interface EmailBuilderManagerInterface extends PluginManagerInterface {
*/
public function getImportInfo();
/**
* Checks if config importing is required.
*
* @return bool
* TRUE if import is required.
*/
public function importRequired();
/**
* Imports config for the specified id.
*
......
......@@ -5,6 +5,9 @@
* Allows sending emails with Symfony Mailer.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_theme().
*/
......@@ -40,3 +43,29 @@ function template_preprocess_email(array &$variables) {
$variables['body'] = $email->getBody();
$variables = array_merge($variables, $email->getVariables());
}
/**
* Implements hook_help().
*/
function symfony_mailer_help($route_name, RouteMatchInterface $route_match) {
// Remind site administrators if there are pending import operations. We
// don't need to issue the message on the import pages.
if ((substr($route_name, 0, strlen('symfony_mailer.import.')) != 'symfony_mailer.import.') && \Drupal::currentUser()->hasPermission('administer mailer') && \Drupal::service('plugin.manager.email_builder')->importRequired()) {
$params = [':import_config' => Url::fromRoute('symfony_mailer.import.status')->toString()];
\Drupal::messenger()->addError(t('There are Mailer configuration import operations pending: <a href=":import_config">import</a>.', $params));
}
switch ($route_name) {
case 'entity.mailer_policy.collection':
return '<p>' . t('Configure Mailer Policy to customise outgoing emails in many different ways. There are many possible policies to apply including: subject; body; addresses (from, to, ...); theme; transport; convert to plain text. Each policy can be set globally or for emails of a specific type.') . '</p>';
case 'symfony_mailer.import.status':
$params = [':mailer_policy' => Url::fromRoute('entity.mailer_policy.collection')->toString()];
$output = '<p>' . t('You can import configuration from existing modules to create an equivalent <a href=":mailer_policy">Mailer Policy</a>. It is recommended to run the import at the beginning, before you start editing policy.') . '</p>';
$output .= '<p>' . t('<b>Warning</b> importing overwrites existing policy. If you have already created working policy then you should skip the import.', $params);
return $output;
case 'symfony_mailer.test':
return '<p>' . t('Verify your Mailer configuration by sending a test email.') . '</p>';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment