class AmazonSesTestForm in Amazon SES 2.0.x
Amazon SES test form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\amazon_ses\Form\AmazonSesFormBase uses AmazonSesHandlerTrait
- class \Drupal\amazon_ses\Form\AmazonSesTestForm
- class \Drupal\amazon_ses\Form\AmazonSesFormBase uses AmazonSesHandlerTrait
Expanded class hierarchy of AmazonSesTestForm
1 string reference to 'AmazonSesTestForm'
File
- src/
Form/ AmazonSesTestForm.php, line 14
Namespace
Drupal\amazon_ses\FormView source
class AmazonSesTestForm extends AmazonSesFormBase {
/**
* The Mail Manager service.
*
* @var \Drupal\Core\Mail\MailManagerInterface
*/
protected $mailManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The config object.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance
->setHandler($container
->get('amazon_ses.handler'))
->setMailManager($container
->get('plugin.manager.mail'))
->setCurrentUser($container
->get('current_user'))
->setConfig($container
->get('config.factory'));
return $instance;
}
/**
* Set the Mail Manager.
*
* @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
* The Mail Manger object.
*
* @return $this
*/
protected function setMailManager(MailManagerInterface $mail_manager) {
$this->mailManager = $mail_manager;
return $this;
}
/**
* Set the current user.
*
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user.
*
* @return $this
*/
protected function setCurrentUser(AccountProxyInterface $current_user) {
$this->currentUser = $current_user;
return $this;
}
/**
* Set the config object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory object.
*
* @return $this
*/
protected function setConfig(ConfigFactoryInterface $config_factory) {
$this->config = $config_factory
->get('amazon_ses.settings');
return $this;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'amazon_ses_test_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'amazon_ses.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['to'] = [
'#type' => 'textfield',
'#title' => $this
->t('Email'),
'#description' => $this
->t('Enter an email address to send a test mail to.'),
'#default_value' => $this->currentUser
->getEmail(),
'#required' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Send'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$to = $form_state
->getValue('to');
$from = $this->config
->get('from_address');
$body = $this
->t('This is a test of the Amazon SES module. The module has
been configured successfully!');
$message = [
'to' => $to,
'from' => $from,
'subject' => $this
->t('Amazon SES test'),
'body' => $body,
];
$message_id = $this->handler
->send($message);
if ($message_id) {
$this
->messenger()
->addMessage($this
->t('A test message was sent to %to.', [
'%to' => $to,
]));
}
else {
$this
->messenger()
->addError($this
->t('Error sending message to %to.', [
'%to' => $to,
]));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AmazonSesHandlerTrait:: |
protected | property | The Amazon SES handler service. | |
AmazonSesHandlerTrait:: |
protected | function | Set the handler object. | |
AmazonSesTestForm:: |
protected | property | The config object. | |
AmazonSesTestForm:: |
protected | property | The current user. | |
AmazonSesTestForm:: |
protected | property | The Mail Manager service. | |
AmazonSesTestForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
AmazonSesTestForm:: |
public static | function |
Instantiates a new instance of this class. Overrides AmazonSesFormBase:: |
|
AmazonSesTestForm:: |
protected | function | ||
AmazonSesTestForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AmazonSesTestForm:: |
protected | function | Set the config object. | |
AmazonSesTestForm:: |
protected | function | Set the current user. | |
AmazonSesTestForm:: |
protected | function | Set the Mail Manager. | |
AmazonSesTestForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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. | |
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:: |
72 |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |