CommentForm::actions

protected CommentForm::actions(array $form, FormStateInterface $form_state)

Returns an array of supported actions for the current entity form.

@todo Consider introducing a 'preview' action here, since it is used by many entity types.

Overrides EntityForm::actions

File

core/modules/comment/src/CommentForm.php, line 227

Class

CommentForm
Base handler for comment forms.

Namespace

Drupal\comment

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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->entityManager->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'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Preview'),
    '#access' => $preview_mode != DRUPAL_DISABLED,
    '#submit' => array('::submitForm', '::preview'),
  );
 
  return $element;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.