FarmEntryPoint.php in farmOS 2.x
File
modules/core/api/src/Controller/FarmEntryPoint.php
View source
<?php
namespace Drupal\farm_api\Controller;
use Drupal\Core\Extension\ProfileExtensionList;
use Drupal\Core\Session\AccountInterface;
use Drupal\jsonapi\CacheableResourceResponse;
use Drupal\jsonapi\Controller\EntryPoint;
use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel;
use Drupal\jsonapi\JsonApiResource\NullIncludedData;
use Drupal\jsonapi\JsonApiResource\ResourceObjectData;
use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FarmEntryPoint extends EntryPoint {
protected $farmProfileInfo;
public function __construct(ResourceTypeRepositoryInterface $resource_type_repository, AccountInterface $user, ProfileExtensionList $profile_extension_list) {
parent::__construct($resource_type_repository, $user);
$this->farmProfileInfo = $profile_extension_list
->getExtensionInfo('farm');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('jsonapi.resource_type.repository'), $container
->get('current_user'), $container
->get('extension.list.profile'));
}
public function index() {
global $base_url;
$response = parent::index();
$cacheability = $response
->getCacheableMetadata();
$data = $response
->getResponseData();
$urls = $data
->getLinks();
$meta = $data
->getMeta();
$meta['farm'] = [
'name' => $this
->config('system.site')
->get('name'),
'url' => $base_url,
'version' => $this->farmProfileInfo['version'],
];
\Drupal::moduleHandler()
->alter('farm_api_meta', $meta['farm']);
$new_response = new CacheableResourceResponse(new JsonApiDocumentTopLevel(new ResourceObjectData([]), new NullIncludedData(), $urls, $meta));
$new_response
->addCacheableDependency($cacheability);
return $new_response;
}
}