public function FarmEntryPoint::index in farmOS 2.x
Controller to list all the resources.
Return value
\Drupal\jsonapi\ResourceResponse The response object.
Overrides EntryPoint::index
File
- modules/
core/ api/ src/ Controller/ FarmEntryPoint.php, line 60
Class
- FarmEntryPoint
- Extend the core jsonapi EntryPoint controller.
Namespace
Drupal\farm_api\ControllerCode
public function index() {
// Get the base url.
global $base_url;
// Get normal response cache and data.
/** @var \Drupal\jsonapi\CacheableResourceResponse $response */
$response = parent::index();
$cacheability = $response
->getCacheableMetadata();
$data = $response
->getResponseData();
// Get urls and meta.
$urls = $data
->getLinks();
$meta = $data
->getMeta();
// Add a "farm" object to meta.
$meta['farm'] = [
'name' => $this
->config('system.site')
->get('name'),
'url' => $base_url,
'version' => $this->farmProfileInfo['version'],
];
// Allow modules to add additional meta information.
\Drupal::moduleHandler()
->alter('farm_api_meta', $meta['farm']);
// Build a new response.
$new_response = new CacheableResourceResponse(new JsonApiDocumentTopLevel(new ResourceObjectData([]), new NullIncludedData(), $urls, $meta));
// Add the original response's cacheability.
$new_response
->addCacheableDependency($cacheability);
return $new_response;
}