protected function MessageForm::actions in Message UI 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/ MessageForm.php, line 166
Class
- MessageForm
- Form controller for the message_ui entity edit forms.
Namespace
Drupal\message_ui\FormCode
protected function actions(array $form, FormStateInterface $form_state) {
$element = parent::actions($form, $form_state);
$message = $this->entity;
// @todo : check if we need access control here on form submit.
// Create custom save button with conditional label / value.
$element['save'] = $element['submit'];
if ($message
->isNew()) {
$element['save']['#value'] = t('Create');
}
else {
$element['save']['#value'] = t('Update');
}
$element['save']['#weight'] = 0;
$mid = $message
->id();
$url = is_object($message) && !empty($mid) ? Url::fromRoute('entity.message.canonical', [
'message' => $mid,
]) : Url::fromRoute('message.overview_templates');
$link = Link::fromTextAndUrl(t('Cancel'), $url)
->toString();
// Add a cancel link to the message form actions.
$element['cancel'] = [
'#type' => 'markup',
'#markup' => $link,
];
// Remove the default "Save" button.
$element['submit']['#access'] = FALSE;
return $element;
}