public function ExampleController::findPostsAdvanced in HTTP Client Manager 8.2
Find posts - Advanced usage.
Parameters
int|null $postId: The post Id.
Return value
array The service response.
1 string reference to 'ExampleController::findPostsAdvanced'
- 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 114
Class
- ExampleController
- Class ExampleController.
Namespace
Drupal\http_client_manager_example\ControllerCode
public function findPostsAdvanced($postId = NULL) {
$post_link = empty($postId);
$response = !empty($postId) ? $this->api
->findPost($postId) : $this->api
->findPosts();
if (!empty($postId)) {
$response = [
$postId => $response,
];
}
$build = [];
foreach ($response as $id => $post) {
$build[$id] = $this
->buildPostResponse($post, $post_link, TRUE);
}
return $build;
}