You are here

public function HumansTxtController::content in Humans.txt 8

Same name and namespace in other branches
  1. 2.x src/Controller/HumansTxtController.php \Drupal\humanstxt\Controller\HumansTxtController::content()

Serves the configured humans.txt file.

Return value

\Symfony\Component\HttpFoundation\Response The humans.txt file is a response object with 'text/plain' type.

1 string reference to 'HumansTxtController::content'
humanstxt.routing.yml in ./humanstxt.routing.yml
humanstxt.routing.yml

File

src/Controller/HumansTxtController.php, line 35

Class

HumansTxtController
Class HumansTxtController.

Namespace

Drupal\humanstxt\Controller

Code

public function content() {

  // Extract the config object from the ControllerBase parent class.
  $this->humanstxtConfig = $this
    ->config('humanstxt.settings');

  // Get value from config.
  $content = $this->humanstxtConfig
    ->get('content');

  // Create a new response.
  $response = new CacheableResponse($content, Response::HTTP_OK, [
    'content-type' => 'text/plain',
  ]);

  // Add cache metadata from the response.
  $meta_data = $response
    ->getCacheableMetadata();
  $meta_data
    ->addCacheTags([
    'humanstxt',
  ]);
  return $response;
}