This commit is contained in:
2024-06-19 12:34:03 +02:00
parent fa20453ef8
commit 955745dd21
10 changed files with 358 additions and 32 deletions
+66 -2
View File
@@ -35,10 +35,9 @@ function reha_preprocess_page(&$variables) {
function reha_preprocess_node(&$variables) {
$node = &$variables['node'];
$variables['attributes']['class'][] = 'node-type-' . $node->gettype();
if ($variables['node']->getType() == 'site') {
$fields_to_exclude = [
'field--name-field-image',
'field_image', // Remplacez par le nom machine exact de votre champ image
];
$filtered_content = [];
@@ -55,12 +54,58 @@ function reha_preprocess_node(&$variables) {
$variables['filtered_content'] = $filtered_content;
$variables['image_field_content'] = $image_field_content;
}
}
// /**
// * 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) {
if ($variables['plugin_id'] === "user_login_block") {
@@ -89,6 +134,25 @@ function reha_preprocess_block(&$variables) {
}
}
}
// 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;
// }
}