You are here

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

Build Post response.

Parameters

array $post: The Post response item.

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

bool $advanced: Boolean indicating if we are using the basic or advanced usage.

Return value

array A render array of the post.

2 calls to ExampleController::buildPostResponse()
ExampleController::findPosts in modules/http_client_manager_example/src/Controller/ExampleController.php
Find posts.
ExampleController::findPostsAdvanced in modules/http_client_manager_example/src/Controller/ExampleController.php
Find posts - Advanced usage.

File

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

Class

ExampleController
Class ExampleController.

Namespace

Drupal\http_client_manager_example\Controller

Code

protected function buildPostResponse(array $post, $post_link, $advanced = FALSE) {
  $route = $advanced ? 'http_client_manager_example.find_posts.advanced' : '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['id'],
  ] : [];
  $output = [
    '#type' => 'fieldset',
    '#title' => $post['id'] . ') ' . $post['title'],
    'body' => [
      '#markup' => '<p>' . $post['body'] . '</p>',
    ],
    'link' => [
      '#markup' => Link::createFromRoute($link_text, $route, $route_params)
        ->toString(),
    ],
  ];
  return $output;
}