You are here

protected function Container::roleCheck in GoogleTagManager 8

Determines whether to insert the snippet based on the user role settings.

Return value

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

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

File

src/Entity/Container.php, line 478

Class

Container
Defines the container configuration entity.

Namespace

Drupal\google_tag\Entity

Code

protected function roleCheck() {
  $toggle = $this
    ->get('role_toggle');
  $roles = array_filter($this
    ->get('role_list'));
  if (empty($roles)) {
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED;
  }
  else {
    $satisfied = FALSE;

    // Check user roles against listed roles.
    $satisfied = (bool) array_intersect($roles, \Drupal::currentUser()
      ->getRoles());
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED ? !$satisfied : $satisfied;
  }
  $this
    ->displayMessage('role check @satisfied', [
    '@satisfied' => $satisfied,
  ]);
  return $satisfied;
}