protected function CommentForm::actions in Drupal 9
Same name and namespace in other branches
- 8 core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()
- 10 core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()
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
- core/
modules/ comment/ src/ CommentForm.php, line 251
Class
- CommentForm
- Base handler for comment forms.
Namespace
Drupal\commentCode
protected function actions(array $form, FormStateInterface $form_state) {
$element = parent::actions($form, $form_state);
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $this->entity;
$entity = $comment
->getCommentedEntity();
$field_definition = $this->entityFieldManager
->getFieldDefinitions($entity
->getEntityTypeId(), $entity
->bundle())[$comment
->getFieldName()];
$preview_mode = $field_definition
->getSetting('preview');
// No delete action on the comment form.
unset($element['delete']);
// Mark the submit action as the primary action, when it appears.
$element['submit']['#button_type'] = 'primary';
// Only show the save button if comment previews are optional or if we are
// already previewing the submission.
$element['submit']['#access'] = $comment
->id() && $this->currentUser
->hasPermission('administer comments') || $preview_mode != DRUPAL_REQUIRED || $form_state
->get('comment_preview');
$element['preview'] = [
'#type' => 'submit',
'#value' => $this
->t('Preview'),
'#access' => $preview_mode != DRUPAL_DISABLED,
'#submit' => [
'::submitForm',
'::preview',
],
];
return $element;
}