class PostmarkSettingsForm in Postmark 8
Configure Postmark settings.
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\postmark\Form\PostmarkSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of PostmarkSettingsForm
1 string reference to 'PostmarkSettingsForm'
File
- src/
Form/ PostmarkSettingsForm.php, line 14
Namespace
Drupal\postmark\FormView source
class PostmarkSettingsForm extends ConfigFormBase {
/**
* The core mail manager service.
*
* @var \Drupal\postmark\PostmarkHandler
*/
protected $postmarkHandler;
/**
* Constructs a Postmark settings form.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\postmark\PostmarkHandler $postmark_handler
* The core mail manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, PostmarkHandler $postmark_handler) {
parent::__construct($config_factory);
$this->postmarkHandler = $postmark_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('postmark.mail_handler'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'postmark_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'postmark.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// The user's Postmark API key
$form['postmark_api_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Postmark API Token'),
'#default_value' => $this
->config('postmark.settings')
->get('postmark_api_key'),
'#description' => $this
->t('The Server API token similar to ed742D75-5a45-49b6-a0a1-5b9ec3dc9e5d, generated on the Postmark Server Credentials page.'),
'#required' => TRUE,
];
$form['postmark_sender_signature'] = [
'#type' => 'textfield',
'#title' => $this
->t('Postmark Sender Signature'),
'#default_value' => $this
->config('postmark.settings')
->get('postmark_sender_signature'),
'#description' => $this
->t('The email address configured within Postmark as the Sender Signature for the server associated with the Server API token.'),
'#required' => TRUE,
];
$form['debug'] = [
'#type' => 'details',
'#title' => $this
->t('Debugging'),
'#open' => FALSE,
];
$form['debug']['postmark_debug_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Postmark debugging'),
'#default_value' => $this
->config('postmark.settings')
->get('postmark_debug_mode'),
];
$form['debug']['postmark_debug_email'] = [
'#type' => 'textfield',
'#title' => $this
->t('Enable Postmark debugging email'),
'#default_value' => $this
->config('postmark.settings')
->get('postmark_debug_email'),
'#description' => $this
->t('Use a debugging email, so all system emails will go to this address. Debugging mode must be on for this to work'),
];
$form['debug']['postmark_debug_no_send'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Postmark debugging to not send an email and therefore not use a credit'),
'#default_value' => $this
->config('postmark.settings')
->get('postmark_debug_no_send'),
];
$form['test'] = [
'#type' => 'details',
'#title' => $this
->t('Test email'),
'#open' => FALSE,
];
$form['test']['test_address'] = [
'#type' => 'textfield',
'#title' => $this
->t('Recipient'),
'#default_value' => '',
'#description' => $this
->t('Enter a valid email address to send a test email.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('postmark.settings');
$config
->set('postmark_api_key', $form_state
->getValue('postmark_api_key'))
->set('postmark_sender_signature', $form_state
->getValue('postmark_sender_signature'))
->set('postmark_debug_mode', $form_state
->getValue('postmark_debug_mode'))
->set('postmark_debug_email', $form_state
->getValue('postmark_debug_email'))
->set('postmark_debug_no_send', $form_state
->getValue('postmark_debug_no_send'))
->save();
// If an address is submitted, send a test email message.
$test_address = $form_state
->getValue('test_address');
if ($test_address) {
$message = $this
->t('A test e-mail has been sent to @mail. You may want to check the logs for any error messages.', [
'@mail' => $test_address,
]);
$this
->messenger()
->addWarning($message);
$postmark_message = [
'from' => $form_state
->getValue('postmark_sender_signature'),
'to' => $test_address,
'subject' => $this
->t('Test message from Postmark'),
'text' => $this
->t('Just testing.'),
];
$this->postmarkHandler
->sendMail($postmark_message);
}
parent::submitForm($form, $form_state);
}
}
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. | |
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. | |
PostmarkSettingsForm:: |
protected | property | The core mail manager service. | |
PostmarkSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
PostmarkSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
PostmarkSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
PostmarkSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PostmarkSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
PostmarkSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
PostmarkSettingsForm:: |
public | function |
Constructs a Postmark settings form. Overrides ConfigFormBase:: |
|
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. | |
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. |