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

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
2016-10-29 08:50:40
Comments
Leave a Comment

Please login to continue.