You are here

public function SendSmsMessageAction::getSettingsForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x modules/br_sms/src/Plugin/BusinessRulesAction/SendSmsMessageAction.php \Drupal\br_sms\Plugin\BusinessRulesAction\SendSmsMessageAction::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

modules/br_sms/src/Plugin/BusinessRulesAction/SendSmsMessageAction.php, line 37

Class

SendSmsMessageAction
Class SendSmsMessageAction.

Namespace

Drupal\br_sms\Plugin\BusinessRulesAction

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  $settings['phone_number'] = [
    '#type' => 'textfield',
    '#title' => t('Phone number'),
    '#description' => t('The phone number to send the SMS message. You may use variable or token to fill this information.'),
    '#default_value' => $item
      ->getSettings('phone_number'),
    '#required' => TRUE,
  ];
  $settings['message'] = [
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#description' => t('The SMS message. You may use variable or token to fill this information.'),
    '#default_value' => $item
      ->getSettings('message'),
    '#required' => TRUE,
  ];
  $gateways = [];
  foreach (SmsGateway::loadMultiple() as $sms_gateway) {
    $gateways[$sms_gateway
      ->id()] = $sms_gateway
      ->label();
  }
  $settings['gateway'] = [
    '#type' => 'select',
    '#title' => t('Gateway'),
    '#description' => t('Select a gateway to route the message.'),
    '#options' => $gateways,
    '#empty_option' => '- Select -',
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('gateway'),
  ];
  $settings['options'] = [
    '#type' => 'fieldset',
    '#title' => t('Options'),
  ];
  $settings['skip_queue'] = [];
  $settings['automated'] = [];
  $settings['send_on'] = [];
  $settings['options']['skip_queue'] = [
    '#type' => 'checkbox',
    '#title' => t('Force skip queue'),
    '#description' => t('Send or receive the message immediately. If the gateway-specific skip queue setting is turned on, then this option is already applied.'),
    '#default_value' => $item
      ->getSettings('skip_queue') ?: FALSE,
  ];
  $settings['options']['automated'] = [
    '#type' => 'checkbox',
    '#title' => t('Automated'),
    '#description' => t('Flag this message as automated.'),
    '#default_value' => $item
      ->getSettings('automated') != NULL ? $item
      ->getSettings('automated') : TRUE,
  ];
  $settings['options']['send_on'] = [
    '#type' => 'textfield',
    '#title' => t('Send on'),
    '#description' => t('Send this message on this date. This option only applies to messages in the queue. You may use variable or token to fill this information.'),
    '#default_value' => $item
      ->getSettings('send_on') ?: (string) new DrupalDateTime('now'),
  ];
  return $settings;
}