Custom modules for Pleiade local gov dashboard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
pleiade-custom-modules/module_general_pleiade/module_general_pleiade.module

64 lines
3.0 KiB

<?php
use Drupal\Core\Form\FormStateInterface;
/**
* quick check modules orders of execution (default all zero)
* As e must be sure this one fires after our main lemon modules
* see https://davidjguru.github.io/blog/drupal-tips-altering-order-of-execution-in-resources
*/
/**
* @param $variables
*/
function module_general_pleiade_preprocess_page(&$variables)
{
$config = \Drupal::config('module_general_pleiade.settings');
$colorTheme = $config->get('color_theme');
$numero_telephone_support = $config->get('numero_telephone_support');
$adresse_mail_support = $config->get('adresse_mail_support');
$linkedin = $config->get('linkedin');
$twitter = $config->get('twitter');
$sites_internets = $config->get('sites_internets');
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$sites_internet_current_user = $user->get('field_site_internet')->getValue();
// Add the JS library.
$variables['#attached']['library'][] = 'module_general_pleiade/module_general_pleiade_js';
// Add the CSS library.
// $variables['#attached']['library'][] = 'module_general_pleiade/module_general_pleiade_css';
$variables['#attached']['drupalSettings']['module_general_pleiade']['color_theme'] = $colorTheme;
$variables['#attached']['drupalSettings']['module_general_pleiade']['numero_telephone_support'] = $numero_telephone_support;
$variables['#attached']['drupalSettings']['module_general_pleiade']['adresse_mail_support'] = $adresse_mail_support;
$variables['#attached']['drupalSettings']['module_general_pleiade']['linkedin'] = $linkedin;
$variables['#attached']['drupalSettings']['module_general_pleiade']['twitter'] = $twitter;
$variables['#attached']['drupalSettings']['module_general_pleiade']['sites_internets'] = $sites_internets;
$variables['#attached']['drupalSettings']['module_general_pleiade']['sites_internet_current_user'] = $sites_internet_current_user;
}
function module_general_pleiade_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
if ($form_id == 'user_form') {
$form['#attached']['library'][] = 'module_general_pleiade/module_general_pleiade_js';
$config = \Drupal::config('module_general_pleiade.settings');
$sites_internet = $config->get('sites_internets');
$items = explode("\n", $sites_internet);
foreach ($items as $item) {
// Diviser chaque élément en valeurs en utilisant ":"
list($key, $value1, $value2) = explode(",", $item);
// Ajouter la paire clé-valeur au tableau associatif
$array[$key] = array($value1, $value2);
}
$cookie_groups = explode(", ", $_COOKIE['groups']);
$array_keys = array_keys($array);
$form['field_site_internet']['#access'] = TRUE;
foreach ($array_keys as $commune) {
// Vérifier si la clé est présente dans les clés de $cookie_groups
if (in_array($commune, $cookie_groups)) {
$form['field_site_internet']['#access'] = FALSE;
}
}
}
}