You are here

protected function CommentForm::actions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/CommentForm.php \Drupal\comment\CommentForm::actions()

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 232
Contains \Drupal\comment\CommentForm.

Class

CommentForm
Base for controller 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->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;
}