class ListenerPageController in Evercurrent 8.2
Same name and namespace in other branches
- 8 src/Controller/ListenerPageController.php \Drupal\evercurrent\Controller\ListenerPageController
Creates a callback for listening to the server.
Hierarchy
- class \Drupal\evercurrent\Controller\ListenerPageController
Expanded class hierarchy of ListenerPageController
File
- src/
Controller/ ListenerPageController.php, line 12
Namespace
Drupal\evercurrent\ControllerView source
class ListenerPageController {
/**
* Check for page access. Only if listening is set to true.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Current User account.
*
* @return \Drupal\Core\Access\AccessResult
* Access result fo rthis controller.
*/
public function access(AccountInterface $account) {
$config = \Drupal::config('evercurrent.admin_config');
$listen = $config
->get('listen');
return $listen ? AccessResult::allowed() : AccessResult::forbidden();
}
/**
* Renders the content for a dashboard that is listening.
*
* @return Symfony\Component\HttpFoundation\JsonResponse
* A json response representing the content.
*/
public function content() {
$received = json_decode($_POST['data'], TRUE);
$updateHelper = \Drupal::service('evercurrent.update_helper');
// No key equals error response.
if (!isset($received['key'])) {
$severity = RMH_STATUS_ERROR;
$message = 'Received an invalid request in listening mode.';
$updateHelper
->writeStatus($severity, $message, $output = FALSE);
return $this
->jsonResponse('Malformed data.', 'error');
}
$key = $received['key'];
$result = $updateHelper
->testUpdate($key);
if ($result == TRUE) {
$this
->jsonResponse('Success.', 'status');
}
else {
$this
->jsonResponse('Unknown error.', 'error');
}
return $this
->jsonResponse('Can you see this message?', 'error');
}
/**
* Wrapper function for the json response.
*
* @param mixed $message
* The message we are sending.
* @param string $type
* One of "error" or "status".
*
* @return Symfony\Component\HttpFoundation\JsonResponse
* Message and Type wrapped in a json structure.
*/
public function jsonResponse($message, $type) {
return new JsonResponse([
'data' => [
'message' => $message,
'type' => $type,
],
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ListenerPageController:: |
public | function | Check for page access. Only if listening is set to true. | |
ListenerPageController:: |
public | function | Renders the content for a dashboard that is listening. | |
ListenerPageController:: |
public | function | Wrapper function for the json response. |