les variables prétraiter uniquement pour certains blocs
Question
Est-il possible des variables de prétraiter que pour certains blocs?
J'ai créé cette fonction. mytheme_preprocess_block__aggregator(&$vars)
mais il ne fonctionne pas
- EDIT -
Il semble être fixé dans Drupal 8 https://drupal.org/node/1751194
La solution
Malheureusement, il n'y a aucun moyen de le faire comme ça (semblable à hook_form_alter ()).
La meilleure façon de le faire serait d'utiliser des variables $ [ « bloc »] -> offre d'appliquer des modifications uniquement aux blocs que vous voulez:
function mytheme_preprocess_block(&$variables) {
if ($variables['block']->bid === 'target_block_id') {
// do something for this block
} else if ($variables['block']->bid === 'other_target_block_id') {
// do something else for this other block
}
}
Autres conseils
Juste pour confirmer, dans Drupal 8, vous pouvez écrire des fonctions pour prétraiter blocs spécifiques. Par exemple:
Drupal 8
mytheme_preprocess_block__system_branding_block(&$vars) {
// Make changes to the the system branding block
}
Mais vous pouvez aussi utiliser hook_preprocess_block, et l'ID de plugin:
function mytheme_preprocess_block(&$vars) {
if ($vars['plugin_id'] == 'system_branding_block') {
// Make changes to the the system branding block
}
}
Comme mentionné par Alex, dans Drupal 7 vous devrez en tenir à HOOK_preprocess_block, et un contrôle d'identité:
Drupal 7
mytheme_preprocess_block(&$vars) {
if ($vars['block']->bid === 'target_block_id') {
// make changes to this block
}
}