public function PushNotificationsSendMessageForm::buildForm in Push Notifications 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
- src/
Form/ PushNotificationsSendMessageForm.php, line 25
Class
- PushNotificationsSendMessageForm
- Class PushNotificationsSendMessageForm.
Namespace
Drupal\push_notifications\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['instructions'] = array(
'#type' => 'item',
'#markup' => $this
->t('Compose the elements of your push notification message.'),
);
$form['message'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Push Message'),
'#description' => $this
->t('Compose the message to send out (@limit characters max.)', array(
'@limit' => PUSH_NOTIFICATIONS_APNS_PAYLOAD_SIZE_LIMIT,
)),
'#required' => TRUE,
'#size' => 128,
'#maxlength' => PUSH_NOTIFICATIONS_APNS_PAYLOAD_SIZE_LIMIT,
);
// Only show Android option if GCM Api Key is available..
$recipients_options = array(
PUSH_NOTIFICATIONS_NETWORK_ID_IOS => t('iOS (Apple Push Notifications)'),
);
if (!empty(\Drupal::config('push_notifications.gcm')
->get('api_key'))) {
$recipients_options[PUSH_NOTIFICATIONS_NETWORK_ID_ANDROID] = t('Android (Google Cloud Messaging)');
}
$form['networks'] = array(
'#type' => 'checkboxes',
'#title' => t('Target Networks'),
'#description' => t('Select the networks you want to reach with this message.'),
'#options' => $recipients_options,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send Push Notification'),
);
return $form;
}