function CommentForm::actions

Same name in other branches
  1. 9 core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()
  2. 8.9.x core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()
  3. 10 core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()

Overrides EntityForm::actions

File

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

Class

CommentForm
Base handler for comment forms.

Namespace

Drupal\comment

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.