function _drupal_process_attached_supplement in Drupal 8 Cache Backport 7
Overrides drupal_process_attached().
1 call to _drupal_process_attached_supplement()
- core-attachments-collector.inc in includes/
core-attachments-collector.inc - Attachment Collector functions for the D8 caching system backport.
File
- includes/
core-attachments-collector.inc, line 189 - Attachment Collector functions for the D8 caching system backport.
Code
function _drupal_process_attached_supplement($elements, $group = JS_DEFAULT, $dependency_check = FALSE, $every_page = NULL) {
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast = array();
$drupal_static_fast['render_listeners'] =& drupal_static('drupal_render:render_listeners', array());
$drupal_static_fast['collect_attachments'] =& drupal_static('drupal_process_attached:collect_attachments', TRUE);
}
$render_listeners =& $drupal_static_fast['render_listeners'];
$collect_attachments =& $drupal_static_fast['collect_attachments'];
// If we are collecting attachments and have at least one listener in the
// active render listeners, then put all attachments from $elements into the
// storage of all listeners.
if ($collect_attachments && !empty($render_listeners)) {
foreach ($render_listeners as $listener_id => $listener_storage) {
foreach ($elements['#attached'] as $key => $value) {
if (!isset($render_listeners[$listener_id][$key])) {
$render_listeners[$listener_id][$key] = array();
}
$render_listeners[$listener_id][$key] = array_merge($render_listeners[$listener_id][$key], $value);
}
}
}
// Protect against accidental recursion.
$old_collect_attachments = $collect_attachments;
$collect_attachments = FALSE;
// Add additional types of attachments specified in the render() structure.
// Libraries, JavaScript and CSS have been added already, as they require
// special handling.
foreach ($elements['#attached'] as $callback => $options) {
if (function_exists($callback)) {
foreach ($elements['#attached'][$callback] as $args) {
call_user_func_array($callback, $args);
}
}
}
// Restore old value.
$collect_attachments = $old_collect_attachments;
return TRUE;
}