public function AdsTxtController::build in AdsTxt 8
Serves the configured ads.txt file.
Return value
\Symfony\Component\HttpFoundation\Response The ads.txt file as a response object with 'text/plain' content type.
1 string reference to 'AdsTxtController::build'
File
- src/
Controller/ AdsTxtController.php, line 61
Class
- AdsTxtController
- Provides output ads.txt output.
Namespace
Drupal\adstxt\ControllerCode
public function build() {
$content = [];
$content[] = $this->moduleConfig
->get('content');
// Hook other modules for adding additional lines.
if ($additions = $this->moduleHandler
->invokeAll('adstxt')) {
$content = array_merge($content, $additions);
}
// Trim any extra whitespace and filter out empty strings.
$content = array_map('trim', $content);
$content = array_filter($content);
$content = implode("\n", $content);
if (empty($content)) {
throw new NotFoundHttpException();
}
return new Response($content, 200, [
'Content-Type' => 'text/plain',
]);
}