protected function CommentForm::actions in Comment Permissions 8
Returns an array of supported actions for the current entity form.
This function generates a list of Form API elements which represent actions supported by the current entity form.
@todo Consider introducing a 'preview' action here, since it is used by many entity types.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An array of supported Form API action elements keyed by name.
Overrides CommentForm::actions
File
- src/
CommentForm.php, line 187
Class
- CommentForm
- Override comment entity default from.
Namespace
Drupal\comment_permCode
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');
// Only show the save button if comment previews are optional or if we are
// already previewing the submission.
$element['submit']['#access'] = $comment
->id() && $this
->accessAdministerComment($this->currentUser, $entity
->bundle()) || $preview_mode != DRUPAL_REQUIRED || $form_state
->get('comment_preview');
return $element;
}