diff --git a/core/includes/common.inc b/core/includes/common.inc index 9bcb797..3bd78fc 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3828,6 +3828,12 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { drupal_process_states($elements); } + // Add additional libraries, CSS, JavaScript an other custom + // attached data associated with this element. + if (!empty($elements['#attached'])) { + drupal_process_attached($elements); + } + // Get the children of the element, sorted by weight. $children = Element::children($elements, TRUE); @@ -3873,12 +3879,6 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { $elements['#children'] = $elements['#markup'] . $elements['#children']; } - // Add additional libraries, CSS, JavaScript an other custom - // attached data associated with this element. - if (!empty($elements['#attached'])) { - drupal_process_attached($elements); - } - // Let the theme functions in #theme_wrappers add markup around the rendered // children. // #states and #attached have to be processed before #theme_wrappers, because diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 112010c..fa20f99 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1481,6 +1481,24 @@ function drupal_pre_render_table(array $element) { // Take over $element['#id'] as HTML ID attribute, if not already set. element_set_attributes($element, array('id')); + + // Add sticky headers, if applicable. + if (count($element['#header']) && $element['#sticky']) { + $element['#attached']['library'][] = array('system', 'drupal.tableheader'); + // Add 'sticky-enabled' class to the table to identify it for JS. + // This is needed to target tables constructed by this function. + $element['#attributes']['class'][] = 'sticky-enabled'; + } + // If the table has headers and it should react responsively to columns hidden + // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM + // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors. + if (count($element['#header']) && $element['#responsive']) { + $element['#attached']['library'][] = array('system', 'drupal.tableresponsive'); + // Add 'responsive-enabled' class to the table to identify it for JS. + // This is needed to target tables constructed by this function. + $element['#attributes']['class'][] = 'responsive-enabled'; + } + // If the custom #tabledrag is set and there is a HTML ID, add the table's // HTML ID to the options and attach the behavior. if (!empty($element['#tabledrag']) && isset($element['#attributes']['id'])) { @@ -1588,25 +1606,6 @@ function theme_table($variables) { $responsive = $variables['responsive']; $empty = $variables['empty']; - // Add sticky headers, if applicable. - if (count($header) && $sticky) { - $attached['#attached']['library'][] = array('system', 'drupal.tableheader'); - drupal_render($attached); - // Add 'sticky-enabled' class to the table to identify it for JS. - // This is needed to target tables constructed by this function. - $attributes['class'][] = 'sticky-enabled'; - } - // If the table has headers and it should react responsively to columns hidden - // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM - // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors. - if (count($header) && $responsive) { - $attached['#attached']['library'][] = array('system', 'drupal.tableresponsive'); - drupal_render($attached); - // Add 'responsive-enabled' class to the table to identify it for JS. - // This is needed to target tables constructed by this function. - $attributes['class'][] = 'responsive-enabled'; - } - $output = '\n"; if (isset($caption)) { @@ -2039,6 +2038,30 @@ function _template_preprocess_default_variables() { } /** + * #pre_render callback for the html element type. + * + * @param array $element + * A structured array containing the html element type build properties. + * + * @see system_element_info() + */ +function drupal_pre_render_html(array $element) { + // Add favicon. + if (theme_get_setting('features.favicon')) { + $favicon = theme_get_setting('favicon.url'); + $type = theme_get_setting('favicon.mimetype'); + $element['#attached']['drupal_add_html_head_link'][][] = array( + 'rel' => 'shortcut icon', + 'href' => Url::stripDangerousProtocols($favicon), + 'type' => $type, + ); + } + // HTML5 Shiv + $element['#attached']['library'][] = array('system', 'html5shiv'); + + return $element; +} +/** * Prepares variables for HTML document templates. * * Default template: html.html.twig. @@ -2087,18 +2110,6 @@ function template_preprocess_html(&$variables) { $variables['html_attributes']['lang'] = $language_interface->id; $variables['html_attributes']['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; - // Add favicon. - if (theme_get_setting('features.favicon')) { - $favicon = theme_get_setting('favicon.url'); - $type = theme_get_setting('favicon.mimetype'); - $build['#attached']['drupal_add_html_head_link'][][] = array( - 'rel' => 'shortcut icon', - 'href' => Url::stripDangerousProtocols($favicon), - 'type' => $type, - ); - drupal_render($build); - } - $site_config = \Drupal::config('system.site'); // Construct page title. if ($page->hasTitle()) { @@ -2159,9 +2170,6 @@ function template_preprocess_html(&$variables) { drupal_add_html_head($element, $name); } - $attached['#attached']['library'][] = array('system', 'html5shiv'); - drupal_render($attached); - $variables['page_top'][] = array('#markup' => $page->getBodyTop()); $variables['page_bottom'][] = array('#markup' => $page->getBodyBottom()); diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php index 63e0d9c..821d42d 100644 --- a/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php +++ b/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php @@ -17,7 +17,7 @@ class DefaultHtmlPageRenderer implements HtmlPageRendererInterface { */ public function render(HtmlPage $page) { $render = array( - '#theme' => 'html', + '#type' => 'html', '#page_object' => $page, ); return drupal_render($render); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 685bb48..d3bd8f2 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -264,6 +264,10 @@ function system_hook_info() { */ function system_element_info() { // Top level elements. + $types['html'] = array( + '#theme' => 'html', + '#pre_render' => array('drupal_pre_render_html'), + ); $types['form'] = array( '#method' => 'post', '#action' => request_uri(), @@ -596,6 +600,8 @@ function system_element_info() { '#input' => TRUE, '#tree' => TRUE, '#tableselect' => FALSE, + '#sticky' => FALSE, + '#responsive' => TRUE, '#multiple' => TRUE, '#js_select' => TRUE, '#value_callback' => 'form_type_table_value', @@ -2455,8 +2461,8 @@ function system_user_timezone(&$form, &$form_state) { ); if (!$account->getTimezone() && $account->id() == $user->id() && empty($form_state['input']['timezone'])) { $form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.'); + $form['timezone']['#attached']['library'][] = array('system', 'drupal.timezone'); $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect')); - $form['#attached']['library'][] = array('system', 'drupal.timezone'); } }