You are here

class EmailYamlFormHandler in YAML Form 8

Emails a form submission.

Plugin annotation


@YamlFormHandler(
  id = "email",
  label = @Translation("Email"),
  category = @Translation("Notification"),
  description = @Translation("Sends a form submission via an email."),
  cardinality = \Drupal\yamlform\YamlFormHandlerInterface::CARDINALITY_UNLIMITED,
  results = \Drupal\yamlform\YamlFormHandlerInterface::RESULTS_PROCESSED,
)

Hierarchy

Expanded class hierarchy of EmailYamlFormHandler

1 file declares its use of EmailYamlFormHandler
YamlFormSubmissionResendForm.php in src/Form/YamlFormSubmissionResendForm.php

File

src/Plugin/YamlFormHandler/EmailYamlFormHandler.php, line 32

Namespace

Drupal\yamlform\Plugin\YamlFormHandler
View source
class EmailYamlFormHandler extends YamlFormHandlerBase implements YamlFormHandlerMessageInterface {

  /**
   * A mail manager for sending email.
   *
   * @var \Drupal\Core\Mail\MailManagerInterface
   */
  protected $mailManager;

  /**
   * The configuration object factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The token manager.
   *
   * @var \Drupal\yamlform\YamlFormTranslationManagerInterface
   */
  protected $tokenManager;

  /**
   * Cache of default configuration values.
   *
   * @var array
   */
  protected $defaultValues;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, MailManagerInterface $mail_manager, ConfigFactoryInterface $config_factory, YamlFormTokenManagerInterface $token_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $logger);
    $this->mailManager = $mail_manager;
    $this->configFactory = $config_factory;
    $this->tokenManager = $token_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('logger.factory')
      ->get('yamlform.email'), $container
      ->get('plugin.manager.mail'), $container
      ->get('config.factory'), $container
      ->get('yamlform.token_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getSummary() {
    return [
      '#settings' => $this
        ->getEmailConfiguration(),
    ] + parent::getSummary();
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'to_mail' => 'default',
      'cc_mail' => '',
      'bcc_mail' => '',
      'from_mail' => 'default',
      'from_name' => 'default',
      'subject' => 'default',
      'body' => 'default',
      'excluded_elements' => [],
      'html' => TRUE,
      'attachments' => FALSE,
      'debug' => FALSE,
    ];
  }

  /**
   * Get configuration default values.
   *
   * @return array
   *   Configuration default values.
   */
  protected function getDefaultConfigurationValues() {
    if (isset($this->defaultValues)) {
      return $this->defaultValues;
    }
    $yamlform_settings = $this->configFactory
      ->get('yamlform.settings');
    $site_settings = $this->configFactory
      ->get('system.site');
    $body_format = $this->configuration['html'] ? 'html' : 'text';
    $default_mail = $yamlform_settings
      ->get('mail.default_to_mail') ?: $site_settings
      ->get('mail') ?: ini_get('sendmail_from');
    $this->defaultValues = [
      'to_mail' => $default_mail,
      'cc_mail' => $default_mail,
      'bcc_mail' => $default_mail,
      'from_mail' => $default_mail,
      'from_name' => $yamlform_settings
        ->get('mail.default_from_name') ?: $site_settings
        ->get('name'),
      'subject' => $yamlform_settings
        ->get('mail.default_subject') ?: 'Form submission from: [yamlform_submission:source-entity]',
      'body' => $this
        ->getBodyDefaultValues($body_format),
    ];
    return $this->defaultValues;
  }

  /**
   * Get configuration default value.
   *
   * @param string $name
   *   Configuration name.
   *
   * @return string|array
   *   Configuration default value.
   */
  protected function getDefaultConfigurationValue($name) {
    $default_values = $this
      ->getDefaultConfigurationValues();
    return $default_values[$name];
  }

  /**
   * Get mail configuration values.
   *
   * @return array
   *   An associative array containing email configuration values.
   */
  protected function getEmailConfiguration() {
    $configuration = $this
      ->getConfiguration();
    $email = [];
    foreach ($configuration['settings'] as $key => $value) {
      if ($value === 'default') {
        $email[$key] = $this
          ->getDefaultConfigurationValue($key);
      }
      else {
        $email[$key] = $value;
      }
    }
    return $email;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $mail_element_options = [];
    $text_element_options = [];
    $elements = $this->yamlform
      ->getElementsInitializedAndFlattened();
    foreach ($elements as $key => $element) {
      $title = isset($element['#title']) ? new FormattableMarkup('@title (@key)', [
        '@title' => $element['#title'],
        '@key' => $key,
      ]) : $key;
      if (isset($element['#type']) && in_array($element['#type'], [
        'email',
        'hidden',
        'value',
        'select',
        'radios',
        'textfield',
        'yamlform_email_multiple',
        'yamlform_email_confirm',
      ])) {

        // Note: Token must use the :raw form mail elements.
        // For example a select menu's option value would be used to route an
        // email address.
        $mail_element_options["[yamlform_submission:values:{$key}:raw]"] = $title;
      }
      $text_element_options["[yamlform_submission:values:{$key}:value]"] = $title;
    }
    $default_optgroup = (string) $this
      ->t('Default');
    $elements_optgroup = (string) $this
      ->t('Elements');

    // Disable client-side HTML5 validation which is having issues with hidden
    // element validation.
    // @see http://stackoverflow.com/questions/22148080/an-invalid-form-control-with-name-is-not-focusable
    $form['#attributes']['novalidate'] = 'novalidate';

    // To.
    $form['to'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Send to'),
      '#open' => TRUE,
    ];
    $form['to']['to_mail'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('To email'),
      '#options' => [
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom to email address...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('to_mail'),
        ],
        $elements_optgroup => $mail_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter to email address...'),
      '#other__type' => 'yamlform_email_multiple',
      '#other__allow_tokens' => TRUE,
      '#required' => TRUE,
      '#parents' => [
        'settings',
        'to_mail',
      ],
      '#default_value' => $this->configuration['to_mail'],
    ];
    $form['to']['cc_mail'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('CC email'),
      '#options' => [
        '' => '',
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom CC email address...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('cc_mail'),
        ],
        $elements_optgroup => $mail_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter CC email address...'),
      '#other__type' => 'yamlform_email_multiple',
      '#parents' => [
        'settings',
        'cc_mail',
      ],
      '#other__allow_tokens' => TRUE,
      '#default_value' => $this->configuration['cc_mail'],
    ];
    $form['to']['bcc_mail'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('BCC email'),
      '#options' => [
        '' => '',
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom BCC email address...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('bcc_mail'),
        ],
        $elements_optgroup => $mail_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter BCC email address...'),
      '#other__type' => 'yamlform_email_multiple',
      '#other__allow_tokens' => TRUE,
      '#parents' => [
        'settings',
        'bcc_mail',
      ],
      '#default_value' => $this->configuration['bcc_mail'],
    ];

    // From.
    $form['from'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Send from'),
      '#open' => TRUE,
    ];
    $form['from']['from_mail'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('From email'),
      '#options' => [
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom from email address...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('from_mail'),
        ],
        $elements_optgroup => $mail_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter from email address...'),
      '#other__type' => 'yamlform_email_multiple',
      '#other__allow_tokens' => TRUE,
      '#required' => TRUE,
      '#parents' => [
        'settings',
        'from_mail',
      ],
      '#default_value' => $this->configuration['from_mail'],
    ];
    $form['from']['from_name'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('From name'),
      '#options' => [
        '' => '',
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom from name...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('from_name'),
        ],
        $elements_optgroup => $text_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter from name...'),
      '#parents' => [
        'settings',
        'from_name',
      ],
      '#default_value' => $this->configuration['from_name'],
    ];

    // Message.
    $form['message'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Message'),
      '#open' => TRUE,
    ];
    $form['message']['subject'] = [
      '#type' => 'yamlform_select_other',
      '#title' => $this
        ->t('Subject'),
      '#options' => [
        YamlFormSelectOther::OTHER_OPTION => $this
          ->t('Custom subject...'),
        $default_optgroup => [
          'default' => $this
            ->getDefaultConfigurationValue('subject'),
        ],
        $elements_optgroup => $text_element_options,
      ],
      '#other__placeholder' => $this
        ->t('Enter subject...'),
      '#required' => TRUE,
      '#parents' => [
        'settings',
        'subject',
      ],
      '#default_value' => $this->configuration['subject'],
    ];

    // Body.
    // Building a custom select other element that toggles between
    // HTML (CKEditor) and Plain text (CodeMirror) custom body elements.
    $body_options = [
      YamlFormSelectOther::OTHER_OPTION => $this
        ->t('Custom body...'),
      'default' => $this
        ->t('Default'),
      $elements_optgroup => $text_element_options,
    ];
    $body_default_format = $this->configuration['html'] ? 'html' : 'text';
    $body_default_values = $this
      ->getBodyDefaultValues();
    if (isset($body_options[$this->configuration['body']])) {
      $body_default_value = $this->configuration['body'];
      $body_custom_default_value = $body_default_values[$body_default_format];
    }
    else {
      $body_default_value = YamlFormSelectOther::OTHER_OPTION;
      $body_custom_default_value = $this->configuration['body'];
    }
    $form['message']['body'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Body'),
      '#options' => $body_options,
      '#required' => TRUE,
      '#parents' => [
        'settings',
        'body',
      ],
      '#default_value' => $body_default_value,
    ];
    foreach ($body_default_values as $format => $default_value) {

      // Custom body.
      $custom_default_value = $format === $body_default_format ? $body_custom_default_value : $default_value;
      if ($format == 'html') {
        $form['message']['body_custom_' . $format] = [
          '#type' => 'yamlform_html_editor',
        ];
      }
      else {
        $form['message']['body_custom_' . $format] = [
          '#type' => 'yamlform_codemirror',
          '#mode' => $format,
        ];
      }
      $form['message']['body_custom_' . $format] += [
        '#title' => $this
          ->t('Body custom value (@format)', [
          '@label' => $format,
        ]),
        '#title_display' => 'hidden',
        '#parents' => [
          'settings',
          'body_custom_' . $format,
        ],
        '#default_value' => $custom_default_value,
        '#states' => [
          'visible' => [
            ':input[name="settings[body]"]' => [
              'value' => YamlFormSelectOther::OTHER_OPTION,
            ],
            ':input[name="settings[html]"]' => [
              'checked' => $format == 'html' ? TRUE : FALSE,
            ],
          ],
          'required' => [
            ':input[name="settings[body]"]' => [
              'value' => YamlFormSelectOther::OTHER_OPTION,
            ],
            ':input[name="settings[html]"]' => [
              'checked' => $format == 'html' ? TRUE : FALSE,
            ],
          ],
        ],
      ];

      // Default body.
      $form['message']['body_default_' . $format] = [
        '#type' => 'yamlform_codemirror',
        '#mode' => $format,
        '#title' => $this
          ->t('Body default value (@format)', [
          '@label' => $format,
        ]),
        '#title_display' => 'hidden',
        '#default_value' => $default_value,
        '#attributes' => [
          'readonly' => 'readonly',
          'disabled' => 'disabled',
        ],
        '#states' => [
          'visible' => [
            ':input[name="settings[body]"]' => [
              'value' => 'default',
            ],
            ':input[name="settings[html]"]' => [
              'checked' => $format == 'html' ? TRUE : FALSE,
            ],
          ],
        ],
      ];
    }
    $form['message']['token_tree_link'] = $this->tokenManager
      ->buildTreeLink();

    // Elements.
    $form['elements'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Included email values'),
      '#open' => $this->configuration['excluded_elements'] ? TRUE : FALSE,
    ];
    $form['elements']['excluded_elements'] = [
      '#type' => 'yamlform_excluded_elements',
      '#description' => $this
        ->t('The selected elements will be included in the [yamlform_submission:values] token. Individual values may still be printed if explicitly specified as a [yamlform_submission:values:?] in the email body template.'),
      '#yamlform' => $this->yamlform,
      '#default_value' => $this->configuration['excluded_elements'],
      '#parents' => [
        'settings',
        'excluded_elements',
      ],
    ];

    // Settings.
    $form['settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Settings'),
    ];
    $form['settings']['html'] = [
      '#type' => 'checkbox',
      '#title' => t('Send email as HTML'),
      '#return_value' => TRUE,
      '#access' => $this
        ->supportsHtml(),
      '#parents' => [
        'settings',
        'html',
      ],
      '#default_value' => $this->configuration['html'],
    ];
    $form['settings']['attachments'] = [
      '#type' => 'checkbox',
      '#title' => t('Include files as attachments'),
      '#return_value' => TRUE,
      '#access' => $this
        ->supportsAttachments(),
      '#parents' => [
        'settings',
        'attachments',
      ],
      '#default_value' => $this->configuration['attachments'],
    ];
    $form['settings']['debug'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable debugging'),
      '#description' => $this
        ->t('If checked, sent emails will be displayed onscreen to all users.'),
      '#return_value' => TRUE,
      '#parents' => [
        'settings',
        'debug',
      ],
      '#default_value' => $this->configuration['debug'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $values = $form_state
      ->getValues();

    // Set custom body based on the selected format.
    if ($values['body'] === YamlFormSelectOther::OTHER_OPTION) {
      $body_format = $values['html'] ? 'html' : 'text';
      $values['body'] = $values['body_custom_' . $body_format];
    }
    unset($values['body_custom_text'], $values['body_default_html']);
    foreach ($this->configuration as $name => $value) {
      if (isset($values[$name])) {
        $this->configuration[$name] = $values[$name];
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function postSave(YamlFormSubmissionInterface $yamlform_submission, $update = TRUE) {
    $is_results_disabled = $yamlform_submission
      ->getYamlForm()
      ->getSetting('results_disabled');
    $is_completed = $yamlform_submission
      ->getState() == YamlFormSubmissionInterface::STATE_COMPLETED;
    if ($is_results_disabled || $is_completed) {
      $message = $this
        ->getMessage($yamlform_submission);
      $this
        ->sendMessage($message);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getMessage(YamlFormSubmissionInterface $yamlform_submission) {
    $token_data = [
      'yamlform-submission-options' => [
        'email' => TRUE,
        'excluded_elements' => $this->configuration['excluded_elements'],
        'html' => $this->configuration['html'] && $this
          ->supportsHtml(),
      ],
    ];
    $message = $this->configuration;

    // Replace 'default' values and [tokens] with configuration default values.
    foreach ($message as $key => $value) {
      if ($value === 'default') {
        $message[$key] = $this
          ->getDefaultConfigurationValue($key);
      }
      if (is_string($message[$key])) {
        $message[$key] = $this->tokenManager
          ->replace($message[$key], $yamlform_submission, $token_data);
      }
    }

    // Trim the message body.
    $message['body'] = trim($message['body']);

    // Alter body based on the mail system sender.
    if ($this->configuration['html'] && $this
      ->supportsHtml()) {
      switch ($this
        ->getMailSystemSender()) {
        case 'swiftmailer':

          // SwiftMailer requires that the body be valid Markup.
          $message['body'] = Markup::create($message['body']);
          break;
      }
    }
    else {

      // Since Drupal might be rendering a token into the body as markup
      // we need to decode all HTML entities which are being sent as plain text.
      $message['body'] = html_entity_decode($message['body']);
    }

    // Add attachments.
    $message['attachments'] = [];
    if ($this->configuration['attachments'] && $this
      ->supportsAttachments()) {
      $elements = $this->yamlform
        ->getElementsInitializedAndFlattened();
      foreach ($elements as $key => $element) {
        if (!isset($element['#type']) || $element['#type'] != 'managed_file') {
          continue;
        }
        $fids = $yamlform_submission
          ->getData($key);
        if (empty($fids)) {
          continue;
        }

        /** @var \Drupal\file\FileInterface[] $files */
        $files = File::loadMultiple(is_array($fids) ? $fids : [
          $fids,
        ]);
        foreach ($files as $file) {
          $filepath = \Drupal::service('file_system')
            ->realpath($file
            ->getFileUri());
          $message['attachments'][] = [
            'filecontent' => file_get_contents($filepath),
            'filename' => $file
              ->getFilename(),
            'filemime' => $file
              ->getMimeType(),
            // Add URL to be used by resend webform.
            'file' => $file,
          ];
        }
      }
    }

    // Add form submission.
    $message['yamlform_submission'] = $yamlform_submission;
    return $message;
  }

  /**
   * {@inheritdoc}
   */
  public function sendMessage(array $message) {

    // Send mail.
    $to = $message['to_mail'];
    $from = $message['from_mail'] . ($message['from_name'] ? ' <' . $message['from_name'] . '>' : '');
    $current_langcode = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    $this->mailManager
      ->mail('yamlform', 'email.' . $this
      ->getHandlerId(), $to, $current_langcode, $message, $from);

    // Log message.
    $context = [
      '@form' => $this
        ->getYamlForm()
        ->label(),
      '@title' => $this
        ->label(),
    ];
    $this->logger
      ->notice('@form form sent @title email.', $context);

    // Debug by displaying send email onscreen.
    if ($this->configuration['debug']) {
      $t_args = [
        '%from_name' => $message['from_name'],
        '%from_mail' => $message['from_mail'],
        '%to_mail' => $message['to_mail'],
        '%subject' => $message['subject'],
      ];
      $build = [];
      $build['message'] = [
        '#markup' => $this
          ->t('%subject sent to %to_mail from %from_name [%from_mail].', $t_args),
        '#prefix' => '<b>',
        '#suffix' => '</b>',
      ];
      if ($message['html']) {
        $build['body'] = [
          '#markup' => $message['body'],
          '#allowed_tags' => Xss::getAdminTagList(),
          '#prefix' => '<div>',
          '#suffix' => '</div>',
        ];
      }
      else {
        $build['body'] = [
          '#markup' => $message['body'],
          '#prefix' => '<pre>',
          '#suffix' => '</pre>',
        ];
      }
      drupal_set_message(\Drupal::service('renderer')
        ->render($build), 'warning');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function resendMessageForm(array $message) {
    $element = [];
    $element['to_mail'] = [
      '#type' => 'yamlform_email_multiple',
      '#title' => $this
        ->t('To email'),
      '#default_value' => $message['to_mail'],
    ];
    $element['from_mail'] = [
      '#type' => 'yamlform_email_multiple',
      '#title' => $this
        ->t('From email'),
      '#required' => TRUE,
      '#default_value' => $message['from_mail'],
    ];
    $element['from_name'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('From name'),
      '#required' => TRUE,
      '#default_value' => $message['from_name'],
    ];
    $element['subject'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Subject'),
      '#default_value' => $message['subject'],
    ];
    $body_format = $this->configuration['html'] ? 'html' : 'text';
    $element['body'] = [
      '#type' => 'yamlform_codemirror',
      '#mode' => $body_format,
      '#title' => $this
        ->t('Message (@format)', [
        '@format' => $this->configuration['html'] ? $this
          ->t('HTML') : $this
          ->t('Plain text'),
      ]),
      '#rows' => 10,
      '#required' => TRUE,
      '#default_value' => $message['body'],
    ];
    $element['html'] = [
      '#type' => 'value',
      '#value' => $message['html'],
    ];
    $element['attachments'] = [
      '#type' => 'value',
      '#value' => $message['attachments'],
    ];

    // Display attached files.
    if ($message['attachments']) {
      $file_links = [];
      foreach ($message['attachments'] as $attachment) {
        $file_links[] = [
          '#theme' => 'file_link',
          '#file' => $attachment['file'],
          '#prefix' => '<div>',
          '#suffix' => '</div>',
        ];
      }
      $element['files'] = [
        '#type' => 'item',
        '#title' => $this
          ->t('Attachments'),
        '#markup' => \Drupal::service('renderer')
          ->render($file_links),
      ];
    }
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function getMessageSummary(array $message) {
    return [
      '#settings' => $message,
    ] + parent::getSummary();
  }

  /**
   * Check that HTML emails are supported.
   *
   * @return bool
   *   TRUE if HTML email is supported.
   */
  protected function supportsHtml() {
    return TRUE;
  }

  /**
   * Check that emailing files as attachments is supported.
   *
   * @return bool
   *   TRUE if emailing files as attachments is supported.
   */
  protected function supportsAttachments() {

    // If 'system.mail.interface.default' is 'test_mail_collector' allow
    // email attachments during testing.
    if (\Drupal::configFactory()
      ->get('system.mail')
      ->get('interface.default') == 'test_mail_collector') {
      return TRUE;
    }
    return \Drupal::moduleHandler()
      ->moduleExists('mailsystem');
  }

  /**
   * Get the Mail System's sender module name.
   *
   * @return string
   *   The Mail System's sender module name.
   */
  protected function getMailSystemSender() {
    $mailsystem_config = $this->configFactory
      ->get('mailsystem.settings');
    $mailsystem_sender = $mailsystem_config
      ->get('yamlform.sender') ?: $mailsystem_config
      ->get('defaults.sender');
    return $mailsystem_sender;
  }

  /**
   * Get message body default values, which can be formatted as text or html.
   *
   * @param string $format
   *   If a format (text or html) is provided the default value for the
   *   specified format is return. If no format is specified an associative
   *   array containing the text and html default body values will be returned.
   *
   * @return string|array
   *   A single (text or html) default body value or an associative array
   *   containing both the text and html default body values.
   */
  protected function getBodyDefaultValues($format = NULL) {
    $yamlform_settings = $this->configFactory
      ->get('yamlform.settings');
    $formats = [
      'text' => $yamlform_settings
        ->get('mail.default_body_text') ?: '[yamlform_submission:values]',
      'html' => $yamlform_settings
        ->get('mail.default_body_html') ?: '[yamlform_submission:values]',
    ];
    return $format === NULL ? $formats : $formats[$format];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EmailYamlFormHandler::$configFactory protected property The configuration object factory.
EmailYamlFormHandler::$defaultValues protected property Cache of default configuration values.
EmailYamlFormHandler::$mailManager protected property A mail manager for sending email.
EmailYamlFormHandler::$tokenManager protected property The token manager.
EmailYamlFormHandler::buildConfigurationForm public function Form constructor. Overrides YamlFormHandlerBase::buildConfigurationForm
EmailYamlFormHandler::create public static function Creates an instance of the plugin. Overrides YamlFormHandlerBase::create
EmailYamlFormHandler::defaultConfiguration public function Gets default configuration for this plugin. Overrides YamlFormHandlerBase::defaultConfiguration
EmailYamlFormHandler::getBodyDefaultValues protected function Get message body default values, which can be formatted as text or html.
EmailYamlFormHandler::getDefaultConfigurationValue protected function Get configuration default value.
EmailYamlFormHandler::getDefaultConfigurationValues protected function Get configuration default values.
EmailYamlFormHandler::getEmailConfiguration protected function Get mail configuration values.
EmailYamlFormHandler::getMailSystemSender protected function Get the Mail System's sender module name.
EmailYamlFormHandler::getMessage public function Get a fully populated email for a form submission. Overrides YamlFormHandlerMessageInterface::getMessage
EmailYamlFormHandler::getMessageSummary public function Build message summary. Overrides YamlFormHandlerMessageInterface::getMessageSummary
EmailYamlFormHandler::getSummary public function Returns a render array summarizing the configuration of the form handler. Overrides YamlFormHandlerBase::getSummary
EmailYamlFormHandler::postSave public function Acts on a saved form submission before the insert or update hook is invoked. Overrides YamlFormHandlerBase::postSave
EmailYamlFormHandler::resendMessageForm public function Build resend message form. Overrides YamlFormHandlerMessageInterface::resendMessageForm
EmailYamlFormHandler::sendMessage public function Sends and logs a form submission message. Overrides YamlFormHandlerMessageInterface::sendMessage
EmailYamlFormHandler::submitConfigurationForm public function Form submission handler. Overrides YamlFormHandlerBase::submitConfigurationForm
EmailYamlFormHandler::supportsAttachments protected function Check that emailing files as attachments is supported.
EmailYamlFormHandler::supportsHtml protected function Check that HTML emails are supported.
EmailYamlFormHandler::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides YamlFormHandlerBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
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.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
YamlFormHandlerBase::$handler_id protected property The form handler ID.
YamlFormHandlerBase::$label protected property The form handler label.
YamlFormHandlerBase::$logger protected property A logger instance.
YamlFormHandlerBase::$status protected property The form handler status.
YamlFormHandlerBase::$weight protected property The weight of the form handler.
YamlFormHandlerBase::$yamlform protected property The form .
YamlFormHandlerBase::alterElements public function Alter form submission form elements. Overrides YamlFormHandlerInterface::alterElements 1
YamlFormHandlerBase::alterForm public function Alter form submission form . Overrides YamlFormHandlerInterface::alterForm 1
YamlFormHandlerBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
YamlFormHandlerBase::cardinality public function Returns the form handler cardinality settings. Overrides YamlFormHandlerInterface::cardinality
YamlFormHandlerBase::confirmForm public function Confirm form submission form. Overrides YamlFormHandlerInterface::confirmForm 1
YamlFormHandlerBase::description public function Returns the form handler description. Overrides YamlFormHandlerInterface::description
YamlFormHandlerBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurablePluginInterface::getConfiguration
YamlFormHandlerBase::getHandlerId public function Returns the unique ID representing the form handler. Overrides YamlFormHandlerInterface::getHandlerId
YamlFormHandlerBase::getLabel public function Returns the label of the form handler. Overrides YamlFormHandlerInterface::getLabel
YamlFormHandlerBase::getStatus public function Returns the status of the form handler. Overrides YamlFormHandlerInterface::getStatus
YamlFormHandlerBase::getWeight public function Returns the weight of the form handler. Overrides YamlFormHandlerInterface::getWeight
YamlFormHandlerBase::getYamlForm public function Get the form that this handler is attached to.
YamlFormHandlerBase::init public function Initialize form handler.
YamlFormHandlerBase::isDisabled public function Returns the form handler disabled indicator. Overrides YamlFormHandlerInterface::isDisabled
YamlFormHandlerBase::isEnabled public function Returns the form handler enabled indicator. Overrides YamlFormHandlerInterface::isEnabled 1
YamlFormHandlerBase::label public function Returns the form handler label. Overrides YamlFormHandlerInterface::label
YamlFormHandlerBase::postCreate public function Acts on a form submission after it is created. Overrides YamlFormHandlerInterface::postCreate 1
YamlFormHandlerBase::postDelete public function Acts on deleted a form submission before the delete hook is invoked. Overrides YamlFormHandlerInterface::postDelete 2
YamlFormHandlerBase::postLoad public function Acts on loaded form submission. Overrides YamlFormHandlerInterface::postLoad 1
YamlFormHandlerBase::preCreate public function Changes the values of an entity before it is created. Overrides YamlFormHandlerInterface::preCreate 1
YamlFormHandlerBase::preDelete public function Acts on a form submission before they are deleted and before hooks are invoked. Overrides YamlFormHandlerInterface::preDelete 1
YamlFormHandlerBase::preSave public function Acts on a form submission before the presave hook is invoked. Overrides YamlFormHandlerInterface::preSave 1
YamlFormHandlerBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface::setConfiguration
YamlFormHandlerBase::setHandlerId public function Sets the id for this form handler. Overrides YamlFormHandlerInterface::setHandlerId
YamlFormHandlerBase::setLabel public function Sets the label for this form handler. Overrides YamlFormHandlerInterface::setLabel
YamlFormHandlerBase::setStatus public function Sets the status for this form handler. Overrides YamlFormHandlerInterface::setStatus
YamlFormHandlerBase::setWeight public function Sets the weight for this form handler. Overrides YamlFormHandlerInterface::setWeight
YamlFormHandlerBase::submitForm public function Submit form submission form. Overrides YamlFormHandlerInterface::submitForm 3
YamlFormHandlerBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
YamlFormHandlerBase::validateForm public function Validate form submission form . Overrides YamlFormHandlerInterface::validateForm 1
YamlFormHandlerInterface::CARDINALITY_SINGLE constant Value indicating a single plugin instances are permitted.
YamlFormHandlerInterface::CARDINALITY_UNLIMITED constant Value indicating unlimited plugin instances are permitted.
YamlFormHandlerInterface::RESULTS_IGNORED constant Value indicating form submissions are not processed (ie email or saved) by the handler.
YamlFormHandlerInterface::RESULTS_PROCESSED constant Value indicating form submissions are processed (ie email or saved) by the handler.