iframe_consent-1.0.x-dev/iframe_consent.module

iframe_consent.module
<?php

/**
 * @file
 * Primary module hooks for Iframe Consent module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function iframe_consent_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the iframe_consent module.
    case 'help.page.iframe_consent':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The "Iframe Consent" module is designed to manage the loading of embedded iframes in a GDPR-compliant manner, ensuring that third-party content is only loaded based on the user\'s consent as given in the cookie banner. This prevents iframe loading and helps websites adhere to data protection regulations.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_theme().
 */
function iframe_consent_theme() {
  return [
    'iframe_consent_placeholder' => [
      'variables' => [
        'attributes' => new Attribute(),
        'manage_button_label' => '',
        'manage_button_utility_classes' => '',
        'accept_button_label' => '',
        'display_accept_button' => TRUE,
        'accept_button_utility_classes' => '',
        'body' => '',
        'background' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_alter().
 */
function iframe_consent_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) {

  if ($hook === 'iframe_consent_placeholder') {
    $iframe_consent_helper = \Drupal::service('iframe_consent.helper');

    if (!$iframe_consent_helper->settings->isEnabled()) {
      return;
    }

    $suggestions[] = 'iframe_consent_placeholder__default';

    if (!$iframe_consent_helper->settings->get('templates_by_domain')) {
      return;
    }

    $template_ids = $iframe_consent_helper->getTemplatesList();
    foreach ($template_ids as $template_id) {
      $template = 'iframe_consent_placeholder__' . $template_id;

      if (!in_array($template, $suggestions)) {
        $suggestions[] = $template;
      }
    }
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function iframe_consent_preprocess_iframe(&$variables) {
  $iframe_consent_settings = \Drupal::service('iframe_consent.settings');
  if ($iframe_consent_settings->isEnabled() === FALSE) {
    return;
  }

  $iframe_consent_helper = \Drupal::service('iframe_consent.helper');
  if (isset($variables['attributes']) && $iframe_consent_helper->isInDomainsList($variables['attributes']['src'])) {
    $variables['attributes'] = $iframe_consent_helper->alterIframeAttributes($variables['attributes']);

    $iframe_consent_helper->attachLibraries($variables);
    $iframe_consent_helper->setCacheTags($variables);
  }
}

/**
 * Implements callback_allowed_values_function().
 *
 * @see options_allowed_values()
 */
function iframe_consent_allowed_values_callback() {
  $iframe_consent_settings = \Drupal::service('iframe_consent.settings');
  return $iframe_consent_settings->getConsentGroupsList();
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc