You are here

public function SendEmail::getSettingsForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesAction/SendEmail.php \Drupal\business_rules\Plugin\BusinessRulesAction\SendEmail::getSettingsForm()

Return the form array.

@internal param array $form

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

\Drupal\business_rules\ItemInterface $item: The configured item.

Return value

array The render array for the settings form.

Overrides BusinessRulesItemPluginBase::getSettingsForm

File

src/Plugin/BusinessRulesAction/SendEmail.php, line 50

Class

SendEmail
Class SendEmail.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  $form_state
    ->set('business_rules_item', $item);

  // Only show settings form if the item is already saved.
  if ($item
    ->isNew()) {
    return [];
  }
  $site_mail = \Drupal::config('system.site')
    ->get('mail');
  $settings['use_site_mail_as_sender'] = [
    '#type' => 'select',
    '#title' => t('Use site mail as sender'),
    '#options' => [
      1 => t('Yes'),
      0 => t('No'),
    ],
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('use_site_mail_as_sender') ?: 0,
    '#description' => t('Use %mail as sender', [
      '%mail' => $site_mail,
    ]),
  ];
  $settings['from'] = [
    '#type' => 'textfield',
    '#title' => t('From'),
    '#default_value' => $item
      ->getSettings('from'),
    '#description' => t('You can use variables on this field.'),
    '#states' => [
      'visible' => [
        'select[name="use_site_mail_as_sender"]' => [
          'value' => '0',
        ],
      ],
    ],
  ];
  $settings['to'] = [
    '#type' => 'textfield',
    '#title' => t('To'),
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('to'),
    '#description' => t('For multiple recipients, use semicolon(;). You can use variables on this field. The variable can contain one email or an array of emails'),
  ];
  $settings['subject'] = [
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#required' => TRUE,
    '#maxlength' => 256,
    '#default_value' => $item
      ->getSettings('subject'),
    '#description' => t('You can use variables on this field.'),
  ];
  $settings['format'] = [
    '#type' => 'select',
    '#title' => t('Mail format'),
    '#options' => [
      'html' => t('HTML'),
      'text' => t('Text'),
    ],
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('format') ? $item
      ->getSettings('format') : 'text',
    '#description' => t('Email body format.'),
  ];
  $settings['body'] = [
    '#type' => 'text_format',
    '#title' => t('Message'),
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('body')['value'],
    '#description' => t('You can use variables on this field.'),
    '#format' => $item
      ->getSettings('body') && isset($item
      ->getSettings('body')['format']) ? $item
      ->getSettings('body')['format'] : 'full_html',
  ];
  return $settings;
}