You are here

public function AdsTxtController::buildAppAds in AdsTxt 8

Serves the configured app-ads.txt file.

Return value

\Symfony\Component\HttpFoundation\Response The app-ads.txt file as a response object with 'text/plain' content type.

1 string reference to 'AdsTxtController::buildAppAds'
adstxt.routing.yml in ./adstxt.routing.yml
adstxt.routing.yml

File

src/Controller/AdsTxtController.php, line 88

Class

AdsTxtController
Provides output ads.txt output.

Namespace

Drupal\adstxt\Controller

Code

public function buildAppAds() {
  $content = [];
  $content[] = $this->moduleConfig
    ->get('app_content');

  // Hook other modules for adding additional lines.
  if ($additions = $this->moduleHandler
    ->invokeAll('app_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',
  ]);
}