You are here

public function ListenerPageController::content in Evercurrent 8.2

Same name and namespace in other branches
  1. 8 src/Controller/ListenerPageController.php \Drupal\evercurrent\Controller\ListenerPageController::content()

Renders the content for a dashboard that is listening.

Return value

Symfony\Component\HttpFoundation\JsonResponse A json response representing the content.

1 string reference to 'ListenerPageController::content'
evercurrent.routing.yml in ./evercurrent.routing.yml
evercurrent.routing.yml

File

src/Controller/ListenerPageController.php, line 35

Class

ListenerPageController
Creates a callback for listening to the server.

Namespace

Drupal\evercurrent\Controller

Code

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');
}