protected function AjaxCommentsController::buildCommentFieldResponse in AJAX Comments 8
Create an ajax response to replace the comment field.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request object.
\Drupal\Core\Ajax\AjaxResponse $response: The response object being built.
\Drupal\Core\Entity\EntityInterface $entity: The entity that has the comment field.
string $field_name: The machine name of the comment field.
int|null $pid: The entity id of the parent comment, if applicable, NULL otherwise.
Return value
\Drupal\Core\Ajax\AjaxResponse The modified ajax response.
4 calls to AjaxCommentsController::buildCommentFieldResponse()
- AjaxCommentsController::add in src/
Controller/ AjaxCommentsController.php - Builds ajax response for adding a new comment without a parent comment.
- AjaxCommentsController::delete in src/
Controller/ AjaxCommentsController.php - Builds ajax response for deleting a comment.
- AjaxCommentsController::replyAccess in src/
Controller/ AjaxCommentsController.php - Check the user's permission to post a comment.
- AjaxCommentsController::save in src/
Controller/ AjaxCommentsController.php - Submit handler for the comment reply and edit forms.
File
- src/
Controller/ AjaxCommentsController.php, line 196
Class
- AjaxCommentsController
- Controller routines for AJAX comments routes.
Namespace
Drupal\ajax_comments\ControllerCode
protected function buildCommentFieldResponse(Request $request, AjaxResponse $response, EntityInterface $entity, $field_name, $pid = NULL) {
// Build a comment field render array for the ajax response.
$comment_display = $this
->renderCommentField($entity, $field_name);
// Get the wrapper HTML id selector.
$selectors = $this->tempStore
->getSelectors($request);
$wrapper_html_id = $selectors['wrapper_html_id'];
// Rendering the comment form below (as part of comment_display) triggers
// form processing.
$response
->addCommand(new ReplaceCommand($wrapper_html_id, $comment_display));
// Store the new wrapper_html_id, in case it is needed for other commands.
$this->tempStore
->setSelector('wrapper_html_id', $comment_display['#attributes']['id']);
return $response;
}