Skip to main content
Add clarifications from comments
Source Link
Beebee
  • 6.9k
  • 2
  • 34
  • 56

For whatever reason (maybe just oversight)Because the render array has already been rendered before the preprocess functions, '#attached' is not supported in preprocess functions until Drupal 8.

The issue where it was added is https://www.drupal.org/node/2346369

The related Drupal 8 change record is https://www.drupal.org/node/2352319 - this also shows the supported way of doing it in Drupal 7.

Using drupal_add_library() will work, but it will not be cached, so you will take a performance hit. You are better off adding it to the #attached array at a different step in the process.

For whatever reason (maybe just oversight), '#attached' is not supported in preprocess functions until Drupal 8.

The issue where it was added is https://www.drupal.org/node/2346369

The related Drupal 8 change record is https://www.drupal.org/node/2352319 - this also shows the supported way of doing it in Drupal 7.

Because the render array has already been rendered before the preprocess functions, '#attached' is not supported in preprocess functions until Drupal 8.

The issue where it was added is https://www.drupal.org/node/2346369

The related Drupal 8 change record is https://www.drupal.org/node/2352319 - this also shows the supported way of doing it in Drupal 7.

Using drupal_add_library() will work, but it will not be cached, so you will take a performance hit. You are better off adding it to the #attached array at a different step in the process.

Source Link
rooby
  • 14.7k
  • 1
  • 40
  • 82

For whatever reason (maybe just oversight), '#attached' is not supported in preprocess functions until Drupal 8.

The issue where it was added is https://www.drupal.org/node/2346369

The related Drupal 8 change record is https://www.drupal.org/node/2352319 - this also shows the supported way of doing it in Drupal 7.