protected function CommentFormController::actions

Overrides Drupal\Core\Entity\EntityFormController::actions().

Overrides EntityFormController::actions

File

drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php, line 198
Definition of Drupal\comment\CommentFormController.

Class

CommentFormController
Base for controller for comment forms.

Namespace

Drupal\comment

Code

protected function actions(array $form, array &$form_state) {
  $element = parent::actions($form, $form_state);
  $comment = $this
    ->getEntity($form_state);
  $node = $form_state['comment']['node'];
  $preview_mode = variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL);

  // 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->cid && user_access('administer comments') || $preview_mode != DRUPAL_REQUIRED || isset($form_state['comment_preview']);
  $element['preview'] = array(
    '#type' => 'submit',
    '#value' => t('Preview'),
    '#access' => $preview_mode != DRUPAL_DISABLED,
    '#validate' => array(
      array(
        $this,
        'validate',
      ),
    ),
    '#submit' => array(
      array(
        $this,
        'submit',
      ),
      array(
        $this,
        'preview',
      ),
    ),
  );
  return $element;
}