You are here

protected function Container::statusCheck in GoogleTagManager 8

Determines whether to insert the snippet based on status code settings.

Return value

bool TRUE if the status conditions are met; FALSE otherwise.

1 call to Container::statusCheck()
Container::insertSnippet in src/Entity/Container.php
Determines whether to insert the snippet on the response.

File

src/Entity/Container.php, line 422

Class

Container
Defines the container configuration entity.

Namespace

Drupal\google_tag\Entity

Code

protected function statusCheck() {
  $toggle = $this
    ->get('status_toggle');
  $statuses = $this
    ->get('status_list');
  if (empty($statuses)) {
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED;
  }
  else {

    // Get the HTTP response status.
    $request = \Drupal::request();
    $status = '200';
    if ($exception = $request->attributes
      ->get('exception')) {
      $status = $exception
        ->getStatusCode();
    }
    $satisfied = strpos($statuses, (string) $status) !== FALSE;
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED ? !$satisfied : $satisfied;
  }
  $this
    ->displayMessage('status check @satisfied', [
    '@satisfied' => $satisfied,
  ]);
  return $satisfied;
}