class EmailBodyForm in Mass Contact 8
Email body settings 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\mass_contact\Form\SettingsFormBase
- class \Drupal\mass_contact\Form\EmailBodyForm
- class \Drupal\mass_contact\Form\SettingsFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of EmailBodyForm
1 file declares its use of EmailBodyForm
- EmailBodyFormTest.php in src/
Tests/ Form/ EmailBodyFormTest.php
1 string reference to 'EmailBodyForm'
File
- src/
Form/ EmailBodyForm.php, line 16
Namespace
Drupal\mass_contact\FormView source
class EmailBodyForm extends SettingsFormBase {
/**
* The Mass Contact helper service.
*
* @var \Drupal\mass_contact\MassContactInterface
*/
protected $massContact;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs the email body form.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\mass_contact\MassContactInterface $mass_contact
* The mass contact helper service.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, MassContactInterface $mass_contact) {
parent::__construct($config_factory);
$this->massContact = $mass_contact;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('mass_contact'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'mass_contact_email_body_settings';
}
/**
* {@inheritdoc}
*/
protected function getConfigKeys() {
return [
'message_format',
'message_prefix',
'message_suffix',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('mass_contact.settings');
// HTML options.
$form['html_settings'] = [
'#type' => 'details',
'#open' => $this->massContact
->htmlSupported(),
'#title' => $this
->t('HTML Settings'),
];
if ($this->massContact
->htmlSupported()) {
$format = $config
->get('message_format');
$options = array_map(function (FilterFormatInterface $filter_format) {
return $filter_format
->label();
}, filter_formats());
$form['html_settings']['message_format'] = [
'#type' => 'select',
'#title' => $this
->t('The default text format'),
'#default_value' => $format,
'#description' => $this
->t('This is the text format that will be initially selected. If you do not want to allow HTML messages, then specify a plain text text format and do not allow it to be overridden below. Keep in mind that the user sending the message may not have access to all the text formats that are available here.'),
'#options' => $options,
];
}
else {
$form['html_settings']['message_format'] = [
'#type' => 'hidden',
'#value' => 'plain_text',
];
$form['html_settings']['no_mimemail'] = [
'#type' => 'item',
'#description' => $this
->t('To use HTML email for mass contact messages, the <a href="@mime">Mime Mail</a> module or <a href="@swift">Swiftmailer</a> module is required', [
'@mime' => Url::fromUri('https://www.drupal.org/project/mimemail')
->toString(),
'@swift' => Url::fromUri('https://www.drupal.org/project/swiftmailer')
->toString(),
]),
];
}
// Supplemental texts that are prepended and/or appended to every message.
$form['supplemental_texts'] = [
'#type' => 'details',
'#open' => $config
->get('message_prefix.value') || $config
->get('message_suffix.value'),
'#title' => $this
->t('Supplemental message body texts'),
'#description' => $this
->t('You may specify additional text to insert before and/or after the message text of every mass email that is sent.'),
];
$form['supplemental_texts']['message_prefix'] = [
'#type' => 'text_format',
'#title' => $this
->t('Text to be prepended to all messages'),
'#default_value' => $config
->get('message_prefix.value'),
'#format' => $config
->get('message_prefix.format'),
'#description' => $this
->t('The text you specify in this field will be added to all Mass Contact messages sent out and will be placed before the message text entered in by the sender.'),
];
$form['supplemental_texts']['message_suffix'] = [
'#type' => 'text_format',
'#title' => $this
->t('Text to be appended to all messages'),
'#default_value' => $config
->get('message_suffix.value'),
'#format' => $config
->get('message_suffix.format'),
'#description' => $this
->t('The text you specify in this field will be added to all Mass Contact messages sent out and will be placed after the message text entered in by the sender.'),
];
if (!$this->massContact
->htmlSupported()) {
$form['supplemental_texts']['message_prefix']['#allowed_formats'] = [
'plain_text',
];
$form['supplemental_texts']['message_suffix']['#allowed_formats'] = [
'plain_text',
];
}
if ($this->moduleHandler
->moduleExists('token')) {
$form['supplemental_texts']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => [
'global',
],
'#theme_wrappers' => [
'form_element',
],
];
}
// Attachment options.
// @todo Port attachment options.
// @see https://www.drupal.org/node/2867544
return $form;
}
}
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 | |
EmailBodyForm:: |
protected | property | The Mass Contact helper service. | |
EmailBodyForm:: |
protected | property | The module handler service. | |
EmailBodyForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
EmailBodyForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
EmailBodyForm:: |
protected | function |
Get config keys to save. Overrides SettingsFormBase:: |
|
EmailBodyForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EmailBodyForm:: |
public | function |
Constructs the email body form. Overrides ConfigFormBase:: |
|
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. | |
SettingsFormBase:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsFormBase:: |
public | function |
Form submission handler. 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. |