class SocialSwiftmailSettingsForm in Open Social 8.9
Same name and namespace in other branches
- 8.2 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.3 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.4 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.5 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.6 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.7 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 8.8 modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 10.3.x modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 10.0.x modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 10.1.x modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- 10.2.x modules/social_features/social_swiftmail/src/Form/SocialSwiftmailSettingsForm.php \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
Class SocialSwiftmailSettingsForm.
@package Drupal\social_swiftmail\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\social_swiftmail\Form\SocialSwiftmailSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SocialSwiftmailSettingsForm
1 string reference to 'SocialSwiftmailSettingsForm'
- social_swiftmail.routing.yml in modules/
social_features/ social_swiftmail/ social_swiftmail.routing.yml - modules/social_features/social_swiftmail/social_swiftmail.routing.yml
File
- modules/
social_features/ social_swiftmail/ src/ Form/ SocialSwiftmailSettingsForm.php, line 19
Namespace
Drupal\social_swiftmail\FormView source
class SocialSwiftmailSettingsForm extends ConfigFormBase {
/**
* The 'email' activity destination plugin.
*
* @var \Drupal\activity_send_email\Plugin\ActivityDestination\EmailActivityDestination
*/
protected $emailActivityDestination;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* SocialSwiftmailSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\activity_creator\Plugin\ActivityDestinationManager $activity_destination_manager
* The activity destination manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ConfigFactoryInterface $config_factory, ActivityDestinationManager $activity_destination_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($config_factory);
$this->emailActivityDestination = $activity_destination_manager
->createInstance('email');
$this->batchBuilder = new BatchBuilder();
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('plugin.manager.activity_destination.processor'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'social_swiftmail.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'social_swiftmail_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('social_swiftmail.settings');
$form['notification'] = [
'#type' => 'details',
'#title' => $this
->t('Default email notification settings'),
'#open' => FALSE,
];
// Settings helper for admins.
$form['notification']['helper'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('<b>Please note:</b> the change below will not impact the users who have changed their default email notification settings.'),
];
// Get grouped default templates.
$items = _activity_send_email_default_template_items();
// Get all message templates.
$email_message_templates = $this->emailActivityDestination
->getSendEmailMessageTemplates();
// Alter message templates and add them to specific group.
$this->moduleHandler
->alter('activity_send_email_notifications', $items, $email_message_templates);
// Sort a list of email frequencies by weight.
$email_frequencies = sort_email_frequency_options();
$notification_options = [];
// Place the sorted data in an actual form option.
foreach ($email_frequencies as $option) {
if ($option['id'] !== 'none') {
$notification_options[$option['id']] = $option['name'];
}
}
$template_frequencies = $config
->get('template_frequencies') ?: [];
foreach ($items as $item_id => $item) {
$rows = [];
foreach ($item['templates'] as $template) {
$rows[] = $this
->buildRow($template, $notification_options, $template_frequencies);
}
$form['notification'][$item_id] = [
'#type' => 'table',
'#caption' => [
'#markup' => '<h6>' . $item['title'] . '</h6>',
],
'#rows' => $rows,
];
}
$form['template'] = [
'#type' => 'details',
'#title' => $this
->t('Template configuration'),
'#open' => FALSE,
];
$template_header = $config
->get('template_header');
$form['template']['template_header'] = [
'#title' => $this
->t('Template header'),
'#type' => 'text_format',
'#default_value' => $template_header['value'] ?: '',
'#format' => $template_header['format'] ?: 'mail_html',
'#allowed_formats' => [
'mail_html',
],
'#description' => $this
->t('Enter information you want to show in the email notifications header'),
];
$template_footer = $config
->get('template_footer');
$form['template']['template_footer'] = [
'#title' => $this
->t('Template footer'),
'#type' => 'text_format',
'#default_value' => $template_footer['value'] ?: '',
'#format' => $template_footer['format'] ?: 'mail_html',
'#allowed_formats' => [
'mail_html',
],
'#description' => $this
->t('Enter information you want to show in the email notifications footer'),
];
$form['remove_open_social_branding'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Remove Open Social Branding'),
'#description' => $this
->t('Open Social Branding will be replaced by site name (and slogan if available).'),
'#default_value' => $config
->get('remove_open_social_branding'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
// Save config.
$config = $this
->config('social_swiftmail.settings');
$config
->set('remove_open_social_branding', $form_state
->getValue('remove_open_social_branding'));
// Set notification settings.
$templates = $this->emailActivityDestination
->getSendEmailMessageTemplates();
$user_inputs = $form_state
->getUserInput();
foreach (array_keys($templates) as $template) {
if (isset($user_inputs[$template])) {
$config
->set('template_frequencies.' . $template, $user_inputs[$template]);
}
}
// Set the template header and footer settings.
$config
->set('template_header', $form_state
->getValue('template_header'));
$config
->set('template_footer', $form_state
->getValue('template_footer'));
$config
->save();
}
/**
* Returns row for table.
*
* @param string $template
* Template ID.
* @param array $notification_options
* Array of options.
* @param array $template_frequencies
* Frequencies for all templates from config.
*
* @return array[]
* Row.
*/
private function buildRow($template, array $notification_options, array $template_frequencies) {
$email_message_templates = $this->emailActivityDestination
->getSendEmailMessageTemplates();
$row = [
[
'width' => '50%',
'data' => [
'#plain_text' => $email_message_templates[$template],
],
],
];
$default_value = isset($template_frequencies[$template]) ? $template_frequencies[$template] : 'immediately';
foreach ($notification_options as $notification_id => $notification_option) {
$parents_for_id = [
$template,
$notification_id,
];
$row[] = [
'data' => [
'#type' => 'radio',
'#title' => $notification_option,
'#return_value' => $notification_id,
'#value' => $default_value === $notification_id ? $notification_id : FALSE,
'#name' => $template,
'#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)),
],
];
}
return $row;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SocialSwiftmailSettingsForm:: |
protected | property | The 'email' activity destination plugin. | |
SocialSwiftmailSettingsForm:: |
protected | property | The module handler. | |
SocialSwiftmailSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SocialSwiftmailSettingsForm:: |
private | function | Returns row for table. | |
SocialSwiftmailSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SocialSwiftmailSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SocialSwiftmailSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SocialSwiftmailSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SocialSwiftmailSettingsForm:: |
public | function |
SocialSwiftmailSettingsForm constructor. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |