fix css retour Maud

This commit is contained in:
2024-06-24 17:17:48 +02:00
parent d75d876e7f
commit b7a5c3f375
17 changed files with 241 additions and 269 deletions
+4 -134
View File
@@ -64,111 +64,17 @@ function reha_preprocess_html(&$variables) {
$variables['files_field_content'] = $files_field_content;
$variables['liens_field_content'] = $liens_field_content;
}
// if ($node->getType() == 'site') {
// $blocks_to_exclude = [
// 'block-entity-fieldnodefield-image',
// ];
// $filtered_block_content = [];
// $image_block_content = '';
// foreach ($variables['content'] as $block_name => $field_content) {
// if (!in_array($block_name, $blocks_to_exclude)) {
// $filtered_block_content[$block_name] = $field_content;
// } else {
// $image_block_content = $field_content;
// }
// }
// // Set variables for the template
// $variables['filtered_block_content'] = $filtered_block_content;
// $variables['image_block_content'] = $image_block_content;
// }
}
/**
* Implements hook_preprocess_HOOK() for page templates.
*/
// function reha_preprocess_page(&$variables) {
// // Vérifiez si c'est une page de nœud.
// if ($node = \Drupal::routeMatch()->getParameter('node')) {
// if ($node instanceof \Drupal\node\NodeInterface) {
// // Ajoutez une classe unique basée sur le nid (Node ID).
// $variables['attributes']['class'][] = 'page-node-' . $node->id();
// // Ajoutez un ID unique basé sur le nid.
// $variables['attributes']['id'] = 'page-node-' . $node->id();
// }
// }
// else {
// // Si ce n'est pas une page de nœud, vous pouvez ajouter un ID basé sur le nom de la route.
// $route_name = \Drupal::routeMatch()->getRouteName();
// $variables['attributes']['id'] = 'page-' . str_replace('.', '-', $route_name);
// }
// }
// /**
// * Implements hook_preprocess_HOOK() for node templates.
// */
// function reha_preprocess_node(&$variables) {
// if ($variables['node']->getType() == 'site') {
// $fields_to_exclude = [
// 'field--type-image', // Remplacez par le nom machine exact de votre champ image
// ];
// $filtered_content = [];
// $image_field_content = '';
// foreach ($variables['content'] as $field_name => $field_content) {
// if (!in_array($field_name, $fields_to_exclude)) {
// $filtered_content[$field_name] = $field_content;
// } else {
// $image_field_content = $field_content;
// }
// }
// $variables['filtered_content'] = $filtered_content;
// $variables['image_field_content'] = $image_field_content;
// }
// }
/**
* Prepares variables for block templates.
*
* Default template: block.html.twig.
*
* Prepares the values passed to the theme_block function to be passed
* into a pluggable template engine. Uses block properties to generate a
* series of template file suggestions. If none are found, the default
* block.html.twig is used.
*
* Most themes use their own copy of block.html.twig. The default is located
* inside "core/modules/block/templates/block.html.twig". Look in there for the
* full list of available variables.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the properties of the element.
* Properties used: #block, #configuration, #children, #plugin_id.
*/
//https://www.hashbangcode.com/article/drupal-9-programmatically-creating-and-using-urls-and-links
function reha_preprocess_block(&$variables) {
// Conserver les IDs existants et générer un ID unique uniquement si aucun ID n'est présent
if (empty($variables['attributes']['id'])) {
$block_id = 'block-' . uniqid();
$variables['attributes']['id'] = $block_id;
}
if (empty($variables['attributes']['id'])) {
$block_id = 'block-' . uniqid();
$variables['attributes']['id'] = $block_id;
}
if ($variables['plugin_id'] === "user_login_block") {
$url = new Url('user.register', [], ['query' => ['destination' => '/node/add/operation']]);
@@ -195,42 +101,6 @@ function reha_preprocess_block(&$variables) {
];
}
}
// // Extraction du texte du <h2> et transformation en ID
// if (isset($variables['content']['#contextual_links']['block']['h2'])) {
// $h2_text = $variables['content']['#contextual_links']['block']['h2'];
// $block_id = Html::cleanCssIdentifier($h2_text);
// $variables['attributes']['id'] = $block_id;
// } elseif (isset($variables['content']['#block_content']['body']['0']['#text'])) {
// $h2_text = $variables['content']['#block_content']['body']['0']['#text'];
// $block_id = Html::cleanCssIdentifier(strip_tags($h2_text));
// $variables['attributes']['id'] = $block_id;
// } else {
// // Fallback ID if no <h2> is found
// $block_id = Html::cleanCssIdentifier($variables['plugin_id']);
// $variables['attributes']['id'] = $block_id;
// }
}
// if ($variables['plugin_id'] == 'actus-block-1') {
// $fields_to_exclude = [
// 'field_image', // Remplacez par le nom machine exact du champ que vous souhaitez exclure
// ];
// $filtered_content = [];
// $excluded_field_content = '';
// foreach ($variables['content'] as $field_name => $field_content) {
// if (!in_array($field_name, $fields_to_exclude)) {
// $filtered_content[$field_name] = $field_content;
// } else {
// $excluded_field_content = $field_content;
// }
// }
// $variables['filtered_content'] = $filtered_content;
// $variables['excluded_field_content'] = $excluded_field_content;
// }
}