public function SmsDevelMessageForm::buildForm in SMS Framework 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
sms_devel/ src/ Form/ SmsDevelMessageForm.php, line 66
Class
- SmsDevelMessageForm
- Simulate a message being sent or received.
Namespace
Drupal\sms_devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$results = $form_state
->getTemporaryValue('results');
if ($results) {
$form = array_merge($form, $this
->verboseResults($results));
}
$form['number'] = [
'#type' => 'tel',
'#title' => $this
->t('Phone number'),
'#required' => TRUE,
];
$form['message'] = [
'#type' => 'textarea',
'#title' => $this
->t('Message'),
'#required' => TRUE,
];
$gateways = [];
foreach (SmsGateway::loadMultiple() as $sms_gateway) {
$gateways[$sms_gateway
->id()] = $sms_gateway
->label();
}
$form['gateway'] = [
'#type' => 'select',
'#title' => $this
->t('Gateway'),
'#description' => $this
->t('Select a gateway to route the message. The <em>automatic</em> option uses internal rules to decide the destination gateway. The <em>automatic</em> option can not be used if receiving a message.'),
'#options' => $gateways,
'#empty_option' => '- Automatic -',
];
$form['options'] = [
'#type' => 'details',
'#title' => $this
->t('Options'),
'#open' => TRUE,
];
$form['options']['skip_queue'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Force skip queue'),
'#description' => $this
->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' => TRUE,
'#name' => 'skip_queue',
];
$form['options']['automated'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automated'),
'#description' => $this
->t('Flag this message as automated.'),
'#default_value' => TRUE,
];
$form['options']['verbose'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Verbose output'),
'#description' => $this
->t('Show full details of messages.'),
'#default_value' => TRUE,
'#states' => [
'visible' => [
':input[name="' . $form['options']['skip_queue']['#name'] . '"]' => [
'checked' => TRUE,
],
],
],
];
$form['options']['send_on'] = [
'#type' => 'datetime',
'#title' => $this
->t('Send on'),
'#description' => $this
->t('Send this message on this date. This option only applies to messages in the queue.'),
'#default_value' => new DrupalDateTime('now'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['receive'] = [
'#type' => 'submit',
'#name' => 'receive',
'#value' => $this
->t('Receive'),
'#submit' => [
'::submitReceive',
],
];
$form['actions']['submit'] = [
'#name' => 'send',
'#type' => 'submit',
'#value' => $this
->t('Send'),
'#submit' => [
'::submitSend',
],
];
return $form;
}