public function RobotsTxtController::content in RobotsTxt 8
Serves the configured robots.txt file.
Return value
\Symfony\Component\HttpFoundation\Response The robots.txt file as a response object with 'text/plain' content type.
2 string references to 'RobotsTxtController::content'
- robotstxt.routing.yml in ./robotstxt.routing.yml 
- robotstxt.routing.yml
- robotstxt_test.routing.yml in tests/modules/ robotstxt_test/ robotstxt_test.routing.yml 
- tests/modules/robotstxt_test/robotstxt_test.routing.yml
File
- src/Controller/ RobotsTxtController.php, line 61 
Class
- RobotsTxtController
- Provides output robots.txt output.
Namespace
Drupal\robotstxt\ControllerCode
public function content() {
  $content = [];
  $content[] = $this->moduleConfig
    ->get('content');
  // Hook other modules for adding additional lines.
  if ($additions = $this->moduleHandler
    ->invokeAll('robotstxt')) {
    $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);
  $response = new CacheableResponse($content, Response::HTTP_OK, [
    'content-type' => 'text/plain',
  ]);
  $meta_data = $response
    ->getCacheableMetadata();
  $meta_data
    ->addCacheTags([
    'robotstxt',
  ]);
  return $response;
}