You are here

protected function ExampleController::buildPostResponse 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::buildPostResponse()

Build Post response.

Parameters

\Drupal\http_client_manager_example\Response\FindPostsResponse $post: The Post response object.

bool $post_link: TRUE for a "Read more" link, otherwise "Back to list" link.

Return value

array A render array of the post.

1 call to ExampleController::buildPostResponse()
ExampleController::findPosts in modules/http_client_manager_example/src/Controller/ExampleController.php
Find posts.

File

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

Class

ExampleController
Class ExampleController.

Namespace

Drupal\http_client_manager_example\Controller

Code

protected function buildPostResponse(FindPostsResponse $post, $post_link) {
  $route = 'http_client_manager_example.find_posts';
  $link_text = $post_link ? $this
    ->t('Read more') : $this
    ->t('Back to list');
  $route_params = $post_link ? [
    'postId' => $post
      ->getId(),
  ] : [];
  $output = [
    '#type' => 'fieldset',
    '#title' => $post
      ->getId() . ') ' . $post
      ->getTitle(),
    'body' => [
      '#markup' => '<p>' . $post
        ->getBody() . '</p>',
    ],
    'link' => [
      '#markup' => Link::createFromRoute($link_text, $route, $route_params)
        ->toString(),
    ],
  ];
  return $output;
}