You are here

public function Container::noscriptTag in GoogleTagManager 8

Returns tag array for the snippet type.

Parameters

string $type: (optional) The snippet type.

int $weight: (optional) The weight of the item.

Return value

array The tag array.

File

src/Entity/Container.php, line 609

Class

Container
Defines the container configuration entity.

Namespace

Drupal\google_tag\Entity

Code

public function noscriptTag($type = 'noscript', $weight = -10) {

  // Note: depending on the theme, this may not place the snippet immediately
  // after the body tag but should be close and it can be altered.
  // @see https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/group/theme_render/8.2.x
  // The markup is passed through \Drupal\Component\Utility\Xss::filterAdmin()
  // which strips known vectors while allowing a permissive list of HTML tags
  // that are not XSS vectors. (e.g., <script> and <style> are not allowed.)
  // As markup, core removes the 'style' attribute from the noscript snippet.
  // With the inline template type, core does not alter the noscript snippet.
  $contents = $this
    ->getSnippetContents($type);
  $attachment = $contents ? [
    "google_tag_{$type}_tag__{$this->id()}" => [
      '#type' => 'inline_template',
      '#template' => $contents,
      '#weight' => $weight,
    ],
  ] : [];
  return $attachment;
}