You are here

public function ExampleController::findPosts in HTTP Client Manager 8

Same name and namespace in other branches
  1. 8.2 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

string 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 61

Class

ExampleController
Class ExampleController.

Namespace

Drupal\http_client_manager_example\Controller

Code

public function findPosts($postId = NULL) {
  $client = $this
    ->getClient();

  /** @var FindPostsResponse $response */
  $response = $client
    ->findPosts([
    'postId' => $postId,
  ]);
  $post_link = TRUE;
  if (!empty($postId)) {
    $post_link = FALSE;
    $response = [
      $postId => $response,
    ];
  }
  $build = [];
  foreach ($response as $id => $post) {
    $build[$id] = $this
      ->buildPostResponse($post, $post_link);
  }
  return $build;
}