HttpClientManagerPreview.php in HTTP Client Manager 8
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 extends ControllerBase {
protected $httpServicesApi;
public function __construct(HttpServiceApiHandler $http_services_api) {
$this->httpServicesApi = $http_services_api;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('http_client_manager.http_services_api'));
}
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'],
]),
],
],
];
}
}