You are here

public function PagePolicy::page in General Data Protection Regulation Compliance 8

Constructs page from template.

1 string reference to 'PagePolicy::page'
gdpr_compliance.routing.yml in ./gdpr_compliance.routing.yml
gdpr_compliance.routing.yml

File

src/Controller/PagePolicy.php, line 88

Class

PagePolicy
Controller routines for page routes.

Namespace

Drupal\gdpr_compliance\Controller

Code

public function page(Request $request) {
  $lang = $this->lang;
  $path = $this->moduleHandler
    ->getModule('gdpr_compliance')
    ->getPath();
  $policy_path = DRUPAL_ROOT . "/{$path}/assets/policy/policy-{$lang}.html";
  $changed = FALSE;
  $time = filemtime($policy_path);
  if (is_numeric($time)) {
    $changed = filemtime($policy_path);
    $changed = $this->dataFormatter
      ->format($changed, 'medium');
  }
  $policy = file_get_contents($policy_path);
  $context = [
    'changed' => $changed,
    'url' => $request
      ->getHost(),
    'mail' => $this->configFactory
      ->get('system.site')
      ->get('mail'),
  ];
  $this->moduleHandler
    ->alter('gdpr_compliance_policy', $policy, $context);
  return [
    'policy' => [
      '#type' => 'inline_template',
      '#template' => $policy,
      '#context' => $context,
    ],
  ];
}