You are here

class MessageNotifyUiSenderMailSettingsForm in Message UI 8

Message notify plugin form for email.

Plugin annotation


@MessageNotifyUiSenderSettingsForm(
 id = "message_notify_ui_sender_settings_form",
 label = @Translation("The plugin ID."),
 notify_plugin = "email"
)

Hierarchy

Expanded class hierarchy of MessageNotifyUiSenderMailSettingsForm

File

modules/message_notify_ui/src/Plugin/MessageNotifyUiSenderSettingsForm/MessageNotifyUiSenderMailSettingsForm.php, line 19

Namespace

Drupal\message_notify_ui\Plugin\MessageNotifyUiSenderSettingsForm
View source
class MessageNotifyUiSenderMailSettingsForm extends MessageNotifyUiSenderSettingsFormBase implements MessageNotifyUiSenderSettingsFormInterface {

  /**
   * {@inheritdoc}
   */
  public function form() {
    return [
      'use_custom' => [
        '#type' => 'checkbox',
        '#title' => t('Use custom email'),
        '#description' => t('Use the message owner message'),
      ],
      'email' => [
        '#type' => 'email',
        '#title' => t('Email address'),
        '#description' => t('The email address'),
        '#states' => [
          'visible' => [
            ':input[name="use_custom"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function validate(array $form, FormStateInterface $formState) {
    if ($formState
      ->getValue('use_custom') && !$formState
      ->getValue('email')) {
      $formState
        ->setErrorByName('email', t('The email field cannot be empty.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submit(MessageNotifier $notifier, FormStateInterface $formState) {
    $settings = [];
    if ($formState
      ->getValue('use_custom')) {
      $settings['mail'] = $formState
        ->getValue('email');
    }
    if ($formState
      ->getValue('language')) {
      $settings['language override'] = $formState
        ->getValue($formState
        ->getValue('language'));
    }
    if ($notifier
      ->send($this
      ->getMessage(), $settings, 'email')) {
      \Drupal::messenger()
        ->addMessage(t('The email sent successfully.'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessageNotifyUiSenderMailSettingsForm::form public function The form settings for the plugin. Overrides MessageNotifyUiSenderSettingsFormInterface::form
MessageNotifyUiSenderMailSettingsForm::submit public function Implementing logic for sender which relate to the plugin. Overrides MessageNotifyUiSenderSettingsFormInterface::submit
MessageNotifyUiSenderMailSettingsForm::validate public function Validating the form. Overrides MessageNotifyUiSenderSettingsFormBase::validate
MessageNotifyUiSenderSettingsFormBase::$form protected property The form settings.
MessageNotifyUiSenderSettingsFormBase::$formState protected property The form state interface.
MessageNotifyUiSenderSettingsFormBase::$message protected property The message object.
MessageNotifyUiSenderSettingsFormBase::getForm public function Get the form API element.
MessageNotifyUiSenderSettingsFormBase::getFormState public function Return the form state object.
MessageNotifyUiSenderSettingsFormBase::getMessage public function Get the message object.
MessageNotifyUiSenderSettingsFormBase::setForm public function Setter for the form variable.
MessageNotifyUiSenderSettingsFormBase::setFormState public function Set the form state.
MessageNotifyUiSenderSettingsFormBase::setMessage public function Set the message object.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92