Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/cookie_info / cookie_info.module
Size: Mime:
<?php

use Drupal\Core\Template\Attribute;

/**
 * Implements hook_theme().
 */
function cookie_info_theme() {
  return [
    'cookie_info' => [
      'variables' => [
        'title' => NULL,
        'body' => NULL,
        'open' => NULL,
        'close' => NULL,
        'section_attributes' => [],
      ],
    ],
  ];
}

/**
 * Implements hook_page_bottom().
 */
function cookie_info_page_bottom(array &$page_bottom) {

  // Get current theme
  $theme = \Drupal::theme()->getActiveTheme()->getName();

  // Get system theme settings
  $system_config = \Drupal::config('system.theme');

  if ($theme !== $system_config->get('admin')) {

    $config = \Drupal::config('cookie_info.settings');
    $section_attributes = new Attribute();

    if (!empty($config->get('body.value'))) {
      $page_bottom['cookie_info'] = [
        '#theme' => 'cookie_info',
        '#title' => $config->get('title'),
        '#body' => $config->get('body'),
        '#open' => $config->get('open'),
        '#close' => $config->get('close'),
        '#section_attributes' => $section_attributes,
        '#attached' => [
          'library' => 'cookie_info/cookie_info',
          'drupalSettings' => ['cookie_info' => ['cookie_behavior' => $config->get('show_once') == 1 ? 'display_once' : 'display_until_accepted']] //display_once
        ],
        '#cache' => [
          'tags' => ['cookie_info']
        ]
      ];
    }
  }
}

function template_preprocess_cookie_info(&$variables) {
  $variables['attributes'] = new Attribute($variables['attributes']);
  $variables['section_attributes'] = new Attribute($variables['section_attributes']);
}