You are here

HttpClientManagerPreview.php in HTTP Client Manager 8

Same filename and directory in other branches
  1. 8.2 src/Controller/HttpClientManagerPreview.php

File

src/Controller/HttpClientManagerPreview.php
View source
<?php

namespace Drupal\http_client_manager\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\http_client_manager\HttpServiceApiHandler;

/**
 * Class HttpClientManagerPreview.
 *
 * @package Drupal\http_client_manager\Controller
 */
class HttpClientManagerPreview extends ControllerBase {

  /**
   * Drupal\http_client_manager\HttpServiceApiHandler definition.
   *
   * @var \Drupal\http_client_manager\HttpServiceApiHandler
   */
  protected $httpServicesApi;

  /**
   * {@inheritdoc}
   */
  public function __construct(HttpServiceApiHandler $http_services_api) {
    $this->httpServicesApi = $http_services_api;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('http_client_manager.http_services_api'));
  }

  /**
   * View.
   *
   * @return string
   *   Return Hello string.
   */
  public function view() {
    $servicesApi = $this->httpServicesApi
      ->getServicesApi();
    $header = [
      'id' => $this
        ->t('ID'),
      'title' => $this
        ->t('Title'),
      'base_url' => $this
        ->t('Base URL'),
      'operations' => $this
        ->t('Operations'),
    ];
    $rows = [];
    foreach ($servicesApi as $api) {
      $row = array_intersect_key($api, $header);
      $row['operations']['data'] = $this
        ->buildOperations($api);
      $rows[] = $row;
    }
    return [
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#empty' => $this
        ->t('There are no Http Services Api configured yet.'),
    ];
  }
  protected function buildOperations($api) {
    return [
      '#type' => 'operations',
      '#links' => [
        'view' => [
          'title' => $this
            ->t('View Commands'),
          'url' => Url::fromRoute('http_client_manager.http_service_api_preview_view', [
            'serviceApi' => $api['id'],
          ]),
        ],
      ],
    ];
  }

}

Classes

Namesort descending Description
HttpClientManagerPreview Class HttpClientManagerPreview.