public function Container::insertSnippet in GoogleTagManager 8
Determines whether to insert the snippet on the response.
Return value
bool TRUE if the conditions are met; FALSE otherwise.
File
- src/
Entity/ Container.php, line 391
Class
- Container
- Defines the container configuration entity.
Namespace
Drupal\google_tag\EntityCode
public function insertSnippet() {
static $satisfied = [];
if (!isset($satisfied[$this->id])) {
$id = $this
->get('container_id');
if (empty($id)) {
// No container ID.
return $satisfied[$this->id] = FALSE;
}
$this
->displayMessage('google_tag container ' . $this->id);
$satisfied[$this->id] = TRUE;
if (!$this
->statusCheck() || !$this
->pathCheck() || !$this
->roleCheck() || !$this
->access('view')) {
// Omit snippet if any condition is not met.
$satisfied[$this->id] = FALSE;
}
// Allow other modules to alter the insertion criteria.
\Drupal::moduleHandler()
->alter('google_tag_insert', $satisfied[$this->id], $this);
$this
->displayMessage('after alter @satisfied', [
'@satisfied' => $satisfied[$this->id],
]);
}
return $satisfied[$this->id];
}