You are here

public function ExampleController::findPosts in HTTP Client Manager 8.2

Same name and namespace in other branches
  1. 8 modules/http_client_manager_example/src/Controller/ExampleController.php \Drupal\http_client_manager_example\Controller\ExampleController::findPosts()

Find posts.

Parameters

int|null $postId: The post Id.

Return value

array The service response.

1 string reference to 'ExampleController::findPosts'
http_client_manager_example.routing.yml in modules/http_client_manager_example/http_client_manager_example.routing.yml
modules/http_client_manager_example/http_client_manager_example.routing.yml

File

modules/http_client_manager_example/src/Controller/ExampleController.php, line 80

Class

ExampleController
Class ExampleController.

Namespace

Drupal\http_client_manager_example\Controller

Code

public function findPosts($postId = NULL) {
  $client = $this
    ->getClient();
  $post_link = TRUE;
  $command = 'FindPosts';
  $params = [];
  if (!empty($postId)) {
    $post_link = FALSE;
    $command = 'FindPost';
    $params = [
      'postId' => (int) $postId,
    ];
  }
  $response = $client
    ->call($command, $params);
  if (!empty($postId)) {
    $response = [
      $postId => $response
        ->toArray(),
    ];
  }
  $build = [];
  foreach ($response as $id => $post) {
    $build[$id] = $this
      ->buildPostResponse($post, $post_link);
  }
  return $build;
}