Commit 2214ca4e authored by webchick's avatar webchick

Revert "Issue #2171071 by jessebeach, Wim Leers: Remove drupal_add_library()."

Somehow this broke PHPUnit, so rolling back for now.

This reverts commit 91b465bd.
parent 0b55dcd8
...@@ -2474,7 +2474,7 @@ function drupal_pre_render_scripts($elements) { ...@@ -2474,7 +2474,7 @@ function drupal_pre_render_scripts($elements) {
* FALSE if there were any missing library dependencies; TRUE if all library * FALSE if there were any missing library dependencies; TRUE if all library
* dependencies were met. * dependencies were met.
* *
* @see _drupal_add_library() * @see drupal_add_library()
* @see _drupal_add_js() * @see _drupal_add_js()
* @see _drupal_add_css() * @see _drupal_add_css()
* @see drupal_render() * @see drupal_render()
...@@ -2490,7 +2490,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) { ...@@ -2490,7 +2490,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
// Add the libraries first. // Add the libraries first.
$success = TRUE; $success = TRUE;
foreach ($elements['#attached']['library'] as $library) { foreach ($elements['#attached']['library'] as $library) {
if (_drupal_add_library($library[0], $library[1]) === FALSE) { if (drupal_add_library($library[0], $library[1]) === FALSE) {
$success = FALSE; $success = FALSE;
// Exit if the dependency is missing. // Exit if the dependency is missing.
if ($dependency_check) { if ($dependency_check) {
...@@ -2692,7 +2692,7 @@ function drupal_process_states(&$elements) { ...@@ -2692,7 +2692,7 @@ function drupal_process_states(&$elements) {
* @see hook_library_info() * @see hook_library_info()
* @see hook_library_info_alter() * @see hook_library_info_alter()
*/ */
function _drupal_add_library($module, $name, $every_page = NULL) { function drupal_add_library($module, $name, $every_page = NULL) {
$added = &drupal_static(__FUNCTION__, array()); $added = &drupal_static(__FUNCTION__, array());
// Only process the library if it exists and it was not added already. // Only process the library if it exists and it was not added already.
...@@ -2752,7 +2752,7 @@ function _drupal_add_library($module, $name, $every_page = NULL) { ...@@ -2752,7 +2752,7 @@ function _drupal_add_library($module, $name, $every_page = NULL) {
* or FALSE if it does not exist. If no $name was passed, an associative array * or FALSE if it does not exist. If no $name was passed, an associative array
* of libraries registered by $module is returned (which may be empty). * of libraries registered by $module is returned (which may be empty).
* *
* @see _drupal_add_library() * @see drupal_add_library()
* @see hook_library_info() * @see hook_library_info()
* @see hook_library_info_alter() * @see hook_library_info_alter()
* *
......
...@@ -1566,8 +1566,7 @@ function theme_tableselect($variables) { ...@@ -1566,8 +1566,7 @@ function theme_tableselect($variables) {
// checkboxes/radios in the first table column. // checkboxes/radios in the first table column.
if ($element['#js_select']) { if ($element['#js_select']) {
// Add a "Select all" checkbox. // Add a "Select all" checkbox.
$attached['#attached']['library'][] = array('system', 'drupal.tableselect'); drupal_add_library('system', 'drupal.tableselect');
drupal_render($attached);
array_unshift($header, array('class' => array('select-all'))); array_unshift($header, array('class' => array('select-all')));
} }
else { else {
......
...@@ -1546,8 +1546,7 @@ function theme_table($variables) { ...@@ -1546,8 +1546,7 @@ function theme_table($variables) {
// Add sticky headers, if applicable. // Add sticky headers, if applicable.
if (count($header) && $sticky) { if (count($header) && $sticky) {
$attached['#attached']['library'][] = array('system', 'drupal.tableheader'); drupal_add_library('system', 'drupal.tableheader');
drupal_render($attached);
// Add 'sticky-enabled' class to the table to identify it for JS. // Add 'sticky-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function. // This is needed to target tables constructed by this function.
$attributes['class'][] = 'sticky-enabled'; $attributes['class'][] = 'sticky-enabled';
...@@ -1556,8 +1555,7 @@ function theme_table($variables) { ...@@ -1556,8 +1555,7 @@ function theme_table($variables) {
// with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
// and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors. // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
if (count($header) && $responsive) { if (count($header) && $responsive) {
$attached['#attached']['library'][] = array('system', 'drupal.tableresponsive'); drupal_add_library('system', 'drupal.tableresponsive');
drupal_render($attached);
// Add 'responsive-enabled' class to the table to identify it for JS. // Add 'responsive-enabled' class to the table to identify it for JS.
// This is needed to target tables constructed by this function. // This is needed to target tables constructed by this function.
$attributes['class'][] = 'responsive-enabled'; $attributes['class'][] = 'responsive-enabled';
...@@ -2140,8 +2138,7 @@ function template_preprocess_html(&$variables) { ...@@ -2140,8 +2138,7 @@ function template_preprocess_html(&$variables) {
drupal_add_html_head($element, $name); drupal_add_html_head($element, $name);
} }
$attached['#attached']['library'][] = array('system', 'html5shiv'); drupal_add_library('system', 'html5shiv', TRUE);
drupal_render($attached);
$variables['page_top'][] = array('#markup' => $page->getBodyTop()); $variables['page_top'][] = array('#markup' => $page->getBodyTop());
$variables['page_bottom'][] = array('#markup' => $page->getBodyBottom()); $variables['page_bottom'][] = array('#markup' => $page->getBodyBottom());
......
...@@ -124,9 +124,7 @@ public function setDialogTitle($title) { ...@@ -124,9 +124,7 @@ public function setDialogTitle($title) {
*/ */
public function render() { public function render() {
// Add the library for handling the dialog in the response. // Add the library for handling the dialog in the response.
$attached['#attached']['library'][] = array('system', 'drupal.dialog.ajax'); drupal_add_library('system', 'drupal.dialog.ajax');
drupal_render($attached);
// For consistency ensure the modal option is set to TRUE or FALSE. // For consistency ensure the modal option is set to TRUE or FALSE.
$this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal']; $this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal'];
......
...@@ -121,9 +121,9 @@ function testExportTranslation() { ...@@ -121,9 +121,9 @@ function testExportTranslation() {
* Test exportation of translation template file. * Test exportation of translation template file.
*/ */
function testExportTranslationTemplateFile() { function testExportTranslationTemplateFile() {
// Load an admin page with JavaScript so _drupal_add_library() fires at // Load an admin page with JavaScript so drupal_add_library() fires at least
// least once and _locale_parse_js_file() gets to run at least once so that // once and _locale_parse_js_file() gets to run at least once so that the
// the locales_source table gets populated with something. // locales_source table gets populated with something.
$this->drupalGet('admin/config/regional/language'); $this->drupalGet('admin/config/regional/language');
// Get the translation template file. // Get the translation template file.
$this->drupalPostForm('admin/config/regional/translate/export', array(), t('Export')); $this->drupalPostForm('admin/config/regional/translate/export', array(), t('Export'));
......
...@@ -36,8 +36,7 @@ public static function getInfo() { ...@@ -36,8 +36,7 @@ public static function getInfo() {
* @see locale_library_info_alter() * @see locale_library_info_alter()
*/ */
public function testLibraryInfoAlter() { public function testLibraryInfoAlter() {
$attached['#attached']['library'][] = array('system', 'jquery.ui.datepicker'); drupal_add_library('system', 'jquery.ui.datepicker');
drupal_render($attached);
$scripts = drupal_get_js(); $scripts = drupal_get_js();
$this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.'); $this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.');
} }
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
function theme_simpletest_test_table($variables) { function theme_simpletest_test_table($variables) {
$table = $variables['table']; $table = $variables['table'];
drupal_add_library('simpletest', 'drupal.simpletest');
// Create header for test selection table. // Create header for test selection table.
$header = array( $header = array(
array('class' => array('select-all')), array('class' => array('select-all')),
...@@ -131,7 +133,6 @@ function theme_simpletest_test_table($variables) { ...@@ -131,7 +133,6 @@ function theme_simpletest_test_table($variables) {
// Add js array of settings. // Add js array of settings.
$attached = array(); $attached = array();
$attached['#attached']['library'][] = array('simpletest', 'drupal.simpletest');
$attached['#attached']['js'][] = array( $attached['#attached']['js'][] = array(
'data' => array('simpleTest' => $js), 'data' => array('simpleTest' => $js),
'type' => 'setting', 'type' => 'setting',
......
...@@ -311,7 +311,7 @@ function hook_js_alter(&$javascript) { ...@@ -311,7 +311,7 @@ function hook_js_alter(&$javascript) {
* An array defining libraries associated with a module. * An array defining libraries associated with a module.
* *
* @see system_library_info() * @see system_library_info()
* @see _drupal_add_library() * @see drupal_add_library()
* @see drupal_get_library() * @see drupal_get_library()
*/ */
function hook_library_info() { function hook_library_info() {
......
...@@ -1260,7 +1260,6 @@ function system_library_info() { ...@@ -1260,7 +1260,6 @@ function system_library_info() {
'version' => '3.6.2', 'version' => '3.6.2',
'js' => array( 'js' => array(
'core/assets/vendor/html5shiv/html5.js' => array( 'core/assets/vendor/html5shiv/html5.js' => array(
'every_page' => TRUE,
'group' => JS_LIBRARY, 'group' => JS_LIBRARY,
'weight' => -22, 'weight' => -22,
'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE),
...@@ -2184,7 +2183,7 @@ function system_user_timezone(&$form, &$form_state) { ...@@ -2184,7 +2183,7 @@ function system_user_timezone(&$form, &$form_state) {
if (!$account->getTimezone() && $account->id() == $user->id() && empty($form_state['input']['timezone'])) { 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']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.');
$form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect')); $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
$form['#attached']['library'][] = array('system', 'drupal.timezone'); drupal_add_library('system', 'drupal.timezone');
} }
} }
......
...@@ -360,8 +360,7 @@ function views_preprocess_page(&$variables) { ...@@ -360,8 +360,7 @@ function views_preprocess_page(&$variables) {
unset($class[$key]); unset($class[$key]);
$attributes['class'] = $class; $attributes['class'] = $class;
$attributes['data-views-page-contextual-id'] = $variables['title_suffix']['contextual_links']['#id']; $attributes['data-views-page-contextual-id'] = $variables['title_suffix']['contextual_links']['#id'];
$attached['#attached']['library'][] = array('views', 'views.contextual-links'); drupal_add_library('views', 'views.contextual-links');
drupal_render($attached);
} }
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest. * Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest.
*/ */
namespace Drupal\Tests\Core\Ajax; namespace Drupal\Tests\Core\Ajax {
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\Core\Ajax\AddCssCommand; use Drupal\Core\Ajax\AddCssCommand;
...@@ -424,3 +424,13 @@ public function testRedirectCommand() { ...@@ -424,3 +424,13 @@ public function testRedirectCommand() {
} }
} }
}
namespace {
if (!function_exists('drupal_add_library')) {
function drupal_add_library() {
return TRUE;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment