Pregunta

¿Es posible las variables de preprocesamiento solo para ciertos bloques? He creado tal función: mytheme_preprocess_block__aggregator(&$vars) Pero no funciona.

-- EDITAR --

Parece estar arreglado en Drupal 8https://drupal.org/node/1751194

¿Fue útil?

Solución

Desafortunadamente, no hay forma de hacerlo así (similar a Hook_Form_alter ()).

La mejor manera de hacerlo sería usar $ variables ['bloque']-> oferta para aplicar modificaciones solo a los bloques que desea:

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
  }
}

Otros consejos

Solo para confirmar, en Drupal 8 puede escribir funciones de preprocesos para bloques específicos. Por ejemplo:

Drupal 8

mytheme_preprocess_block__system_branding_block(&$vars) {
  // Make changes to the the system branding block
}

Pero también puede usar Hook_Process_Block y la ID del complemento:

function mytheme_preprocess_block(&$vars) {
  if ($vars['plugin_id'] == 'system_branding_block') {
    // Make changes to the the system branding block
  }
}

Como lo mencionó Alex, en Drupal 7 tendrá que quedarse con Hook_Process_Block, y una verificación de ID:

Drupal 7

mytheme_preprocess_block(&$vars) {
  if ($vars['block']->bid === 'target_block_id') {
    // make changes to this block
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a drupal.stackexchange
scroll top