function AnnounceTestController::setFeedConfig
Same name in other branches
- 11.x core/modules/announcements_feed/tests/modules/announce_feed_test/src/Controller/AnnounceTestController.php \Drupal\announce_feed_test\Controller\AnnounceTestController::setFeedConfig()
Reads a JSON file and returns the contents as a Response.
This method will replace the string '[CORE_VERSION]' with the current core version to allow testing core version matches.
Parameters
string $json_name: The name of the JSON file without the file extension.
Return value
\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response If a fixture file with the name $json_name + '.json' is found a JsonResponse will be returned using the contents of the file, otherwise a Response will be returned with a 404 status code.
1 string reference to 'AnnounceTestController::setFeedConfig'
- announce_feed_test.routing.yml in core/
modules/ announcements_feed/ tests/ modules/ announce_feed_test/ announce_feed_test.routing.yml - core/modules/announcements_feed/tests/modules/announce_feed_test/announce_feed_test.routing.yml
File
-
core/
modules/ announcements_feed/ tests/ modules/ announce_feed_test/ src/ Controller/ AnnounceTestController.php, line 27
Class
- AnnounceTestController
- Defines a controller to return JSON for security advisory tests.
Namespace
Drupal\announce_feed_test\ControllerCode
public function setFeedConfig(string $json_name) : JsonResponse|Response {
$file = __DIR__ . "/../../../../announce_feed/{$json_name}.json";
$headers = [
'Content-Type' => 'application/json; charset=utf-8',
];
if (!is_file($file)) {
// Return an empty response.
return new Response('', 404, $headers);
}
return new JsonResponse(file_get_contents($file), 200, $headers, TRUE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.