protected function AjaxController::getOldPrivateMessages in Private Message 8
Same name and namespace in other branches
- 8.2 src/Controller/AjaxController.php \Drupal\private_message\Controller\AjaxController::getOldPrivateMessages()
Create an Ajax Command containing old private messages.
Parameters
Drupal\Core\Ajax\AjaxResponse $response: The response to which any commands should be attached.
1 call to AjaxController::getOldPrivateMessages()
- AjaxController::ajaxCallback in src/
Controller/ AjaxController.php - Create AJAX responses for JavaScript requests.
File
- src/
Controller/ AjaxController.php, line 215
Class
- AjaxController
- Controller to handle Ajax requests.
Namespace
Drupal\private_message\ControllerCode
protected function getOldPrivateMessages(AjaxResponse $response) {
$current_request = $this->requestStack
->getCurrentRequest();
$thread_id = $current_request
->get('threadid');
$message_id = $current_request
->get('messageid');
if (is_numeric($thread_id) && is_numeric($message_id)) {
$message_info = $this->privateMessageService
->getPreviousMessages($thread_id, $message_id);
if (count($message_info)) {
$messages = [];
$view_builder = $this->entityManager
->getViewBuilder('private_message');
foreach ($message_info as $message) {
if ($message
->access('view', $this->currentUser)) {
$messages[] = $view_builder
->view($message);
}
}
$response
->addCommand(new PrivateMessageInsertPreviousMessagesCommand($this->renderer
->renderRoot($messages)));
}
else {
$response
->addCommand(new PrivateMessageInsertPreviousMessagesCommand(''));
}
}
}