neuraflow-1.0.0/modules/cookies_neuraflow/cookies_neuraflow.module

modules/cookies_neuraflow/cookies_neuraflow.module
<?php

/**
 * @file
 * Contains cookies_neuraflow.module.
 */

use Drupal\Component\Utility\Html;
use Drupal\cookies\Constants\CookiesConstants;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function cookies_neuraflow_help($route_name, RouteMatchInterface $route_match) : string|\Stringable|array|null {
  switch ($route_name) {
    // Main module help for the cookies_neuraflow module.
    case 'help.page.cookies_neuraflow':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Submodule of cookies to manage neuraflow integration implemented by so named module.') . '</p>';
      return $output;
  }

  return NULL;
}

/**
 * Implements hook_page_attachments().
 */
function cookies_neuraflow_page_attachments(&$variables): void {
  if (in_array('neuraflow/neurabot', $variables['#attached']['library'])) {
    $variables['#attached']['library'][] = 'cookies_neuraflow/neurabot';
  }
}

/**
 * Implements hook_library_info_alter().
 */
function cookies_neuraflow_library_info_alter(array &$libraries, string $extension) : void {
  $doKo = Drupal::service('cookies.knock_out')->doKnockOut();
  if ($doKo && ($extension == 'neuraflow' && isset($libraries['neurabot']))) {
    foreach ($libraries['neurabot']['js'] as $key => $js) {
      $cleanId = Html::cleanCssIdentifier(substr($key, strripos($key, '/') + 1));
      $attr = $libraries['neurabot']['js'][$key]['attributes'] ?? [];
      $libraries['neurabot']['js'][$key]['attributes'] = array_merge($attr, [
        'type' => CookiesConstants::COOKIES_SCRIPT_KO_TYPE,
        'id' => 'cookies-neurabot--' . $cleanId,
        'data-cookieconsent' => 'neurabot',
      ]);
    }
  }
}

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

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