protected function PushNotificationForm::actions in Push Notifications 8
Returns an array of supported actions for the current entity form.
This function generates a list of Form API elements which represent actions supported by the current entity form.
@todo Consider introducing a 'preview' action here, since it is used by many entity types.
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 An array of supported Form API action elements keyed by name.
Overrides EntityForm::actions
File
- src/
Form/ PushNotificationForm.php, line 155 - Contains Drupal\push_notifications\Form\PushNotificationForm.
Class
- PushNotificationForm
- Form controller for the push_notification entity edit forms.
Namespace
Drupal\push_notifications\FormCode
protected function actions(array $form, FormStateInterface $form_state) {
$element = parent::actions($form, $form_state);
$push_notification = $this->entity;
$pushed = $push_notification
->isPushed() ? TRUE : FALSE;
$element['unpushed'] = $element['submit'];
$element['unpushed']['#pushed_status'] = FALSE;
$element['unpushed']['#dropbutton'] = 'save';
if ($push_notification
->isNew()) {
$element['unpushed']['#value'] = $this
->t('Save as a draft');
}
else {
if (!$pushed) {
$element['unpushed']['#value'] = $this
->t('Save and keep in draft mode');
}
else {
unset($element['unpushed']);
}
}
$element['unpushed']['#weight'] = 0;
$element['pushed'] = $element['submit'];
$element['pushed']['#pushed_status'] = FALSE;
$element['pushed']['#dropbutton'] = 'save';
if ($push_notification
->isNew()) {
$element['pushed']['#value'] = $this
->t('Save and send push notification');
$element['pushed']['#pushed_status'] = TRUE;
}
else {
if ($pushed) {
unset($element['pushed']);
drupal_set_message($this
->t('This push notification has already been sent.'), 'warning');
}
else {
$element['pushed']['#value'] = $this
->t('Save and send push notification');
$element['pushed']['#pushed_status'] = TRUE;
}
}
$element['pushed']['#weight'] = 10;
// Remove the "Save" button.
$element['submit']['#access'] = FALSE;
return $element;
}