Frage

Ist es möglich, dass Preprocess -Variablen nur für bestimmte Blöcke? Ich habe eine solche Funktion erstellt: mytheme_preprocess_block__aggregator(&$vars) Aber es funktioniert nicht.

-- BEARBEITEN --

Es scheint in Drupal 8 behoben zu werdenhttps://drupal.org/node/1751194

War es hilfreich?

Lösung

Leider gibt es keine Möglichkeit, dies so zu tun (ähnlich wie bei Hook_form_alter ()).

Der beste Weg, dies zu tun, wäre die Verwendung von $ variablen ['Block']-> Biet, um Änderungen nur auf die gewünschten Blöcke anzuwenden:

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

Andere Tipps

Um zu bestätigen, können Sie in Drupal 8 Präprozessfunktionen für bestimmte Blöcke schreiben. Zum Beispiel:

Drupal 8

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

Sie können aber auch Hook_Proprocess_Block und die Plugin -ID verwenden:

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

Wie von Alex erwähnt, müssen Sie in Drupal 7 bei Hook_Proprocess_Block und einer ID -Überprüfung festhalten:

Drupal 7

mytheme_preprocess_block(&$vars) {
  if ($vars['block']->bid === 'target_block_id') {
    // make changes to this block
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit drupal.stackexchange
scroll top