summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/theme.inc5
-rw-r--r--modules/aggregator/aggregator.info1
-rw-r--r--modules/aggregator/aggregator.module7
-rw-r--r--modules/book/book.info1
-rw-r--r--modules/book/book.module7
-rw-r--r--modules/comment/comment.info1
-rw-r--r--modules/comment/comment.module7
-rw-r--r--modules/field/field.info1
-rw-r--r--modules/field/field.module7
-rw-r--r--modules/forum/forum.info1
-rw-r--r--modules/forum/forum.module7
-rw-r--r--modules/node/node.info1
-rw-r--r--modules/node/node.module7
-rw-r--r--modules/poll/poll.info1
-rw-r--r--modules/poll/poll.module7
-rw-r--r--modules/search/search.info1
-rw-r--r--modules/search/search.module7
-rw-r--r--modules/simpletest/tests/common.test21
-rw-r--r--modules/simpletest/tests/common_test.info2
-rw-r--r--modules/system/system.api.php9
-rw-r--r--modules/system/system.module94
-rw-r--r--modules/user/user.info1
-rw-r--r--modules/user/user.module7
-rw-r--r--themes/bartik/bartik.info2
24 files changed, 113 insertions, 92 deletions
diff --git a/includes/theme.inc b/includes/theme.inc
index adbffbe92..9a2cc0fe0 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -604,9 +604,7 @@ function list_themes($refresh = FALSE) {
}
}
foreach ($theme->info['scripts'] as $script => $path) {
- if (file_exists($path)) {
- $theme->scripts[$script] = $path;
- }
+ $theme->scripts[$script] = $path;
}
if (isset($theme->info['engine'])) {
$theme->engine = $theme->info['engine'];
@@ -2274,6 +2272,7 @@ function template_preprocess_page(&$variables) {
$variables['theme_hook_suggestions'] = $suggestions;
}
}
+
/**
* Process variables for html.tpl.php
*
diff --git a/modules/aggregator/aggregator.info b/modules/aggregator/aggregator.info
index d94344022..ae67bbb83 100644
--- a/modules/aggregator/aggregator.info
+++ b/modules/aggregator/aggregator.info
@@ -13,3 +13,4 @@ files[] = aggregator.processor.inc
files[] = aggregator.install
files[] = aggregator.test
configure = admin/config/services/aggregator/settings
+stylesheets[all][] = aggregator.css
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index b82bb6484..d9afbe66f 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -283,13 +283,6 @@ function _aggregator_category_title($category) {
}
/**
- * Implements hook_init().
- */
-function aggregator_init() {
- drupal_add_css(drupal_get_path('module', 'aggregator') . '/aggregator.css', array('preprocess' => TRUE));
-}
-
-/**
* Find out whether there are any aggregator categories.
*
* @return
diff --git a/modules/book/book.info b/modules/book/book.info
index 8f74f59bc..c9dd5b97e 100644
--- a/modules/book/book.info
+++ b/modules/book/book.info
@@ -10,3 +10,4 @@ files[] = book.pages.inc
files[] = book.install
files[] = book.test
configure = admin/content/book/settings
+stylesheets[all][] = book.css
diff --git a/modules/book/book.module b/modules/book/book.module
index b30acce9b..ef2d83998 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -215,13 +215,6 @@ function book_admin_paths() {
}
/**
- * Implements hook_init().
- */
-function book_init() {
- drupal_add_css(drupal_get_path('module', 'book') . '/book.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_entity_info_alter().
*/
function book_entity_info_alter(&$info) {
diff --git a/modules/comment/comment.info b/modules/comment/comment.info
index 9e2c14b58..b4374c3c6 100644
--- a/modules/comment/comment.info
+++ b/modules/comment/comment.info
@@ -12,3 +12,4 @@ files[] = comment.install
files[] = comment.test
files[] = comment.tokens.inc
configure = admin/content/comment
+stylesheets[all][] = comment.css
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index a8b8a662f..3d8d2a5d6 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -290,13 +290,6 @@ function comment_menu() {
}
/**
- * Implements hook_init().
- */
-function comment_init() {
- drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_menu_alter().
*/
function comment_menu_alter(&$items) {
diff --git a/modules/field/field.info b/modules/field/field.info
index 60c429778..06de4084f 100644
--- a/modules/field/field.info
+++ b/modules/field/field.info
@@ -15,3 +15,4 @@ files[] = field.form.inc
files[] = tests/field.test
dependencies[] = field_sql_storage
required = TRUE
+stylesheets[all][] = theme/field.css
diff --git a/modules/field/field.module b/modules/field/field.module
index 8ecfa4458..fdff56298 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -169,13 +169,6 @@ function field_theme() {
}
/**
- * Implements hook_init().
- */
-function field_init() {
- drupal_add_css(drupal_get_path('module', 'field') . '/theme/field.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_cron().
*
* Purges some deleted Field API data, if any exists.
diff --git a/modules/forum/forum.info b/modules/forum/forum.info
index a6fec2ccb..d4998fc38 100644
--- a/modules/forum/forum.info
+++ b/modules/forum/forum.info
@@ -12,3 +12,4 @@ files[] = forum.pages.inc
files[] = forum.install
files[] = forum.test
configure = admin/structure/forum
+stylesheets[all][] = forum.css
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 5b92d0d2e..bc6a132fc 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -218,13 +218,6 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
}
/**
- * Implements hook_init().
- */
-function forum_init() {
- drupal_add_css(drupal_get_path('module', 'forum') . '/forum.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_entity_info_alter().
*/
function forum_entity_info_alter(&$info) {
diff --git a/modules/node/node.info b/modules/node/node.info
index 51130138d..23cc23099 100644
--- a/modules/node/node.info
+++ b/modules/node/node.info
@@ -13,3 +13,4 @@ files[] = node.test
files[] = node.tokens.inc
required = TRUE
configure = admin/structure/types
+stylesheets[all][] = node.css
diff --git a/modules/node/node.module b/modules/node/node.module
index 8bacba7a5..920e305bc 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2012,13 +2012,6 @@ function _node_custom_theme() {
}
}
-/**
- * Implements hook_init().
- */
-function node_init() {
- drupal_add_css(drupal_get_path('module', 'node') . '/node.css', array('preprocess' => TRUE));
-}
-
function node_last_changed($nid) {
return db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetch()->changed;
}
diff --git a/modules/poll/poll.info b/modules/poll/poll.info
index fd2f3149b..a61b1ec66 100644
--- a/modules/poll/poll.info
+++ b/modules/poll/poll.info
@@ -9,3 +9,4 @@ files[] = poll.pages.inc
files[] = poll.install
files[] = poll.test
files[] = poll.tokens.inc
+stylesheets[all][] = poll.css
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 3d38f46b0..1de52b55f 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -28,13 +28,6 @@ function poll_help($path, $arg) {
}
/**
- * Implements hook_init().
- */
-function poll_init() {
- drupal_add_css(drupal_get_path('module', 'poll') . '/poll.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_theme().
*/
function poll_theme() {
diff --git a/modules/search/search.info b/modules/search/search.info
index eb749d281..1483074a2 100644
--- a/modules/search/search.info
+++ b/modules/search/search.info
@@ -11,3 +11,4 @@ files[] = search.install
files[] = search.test
files[] = search.extender.inc
configure = admin/config/search/settings
+stylesheets[all][] = search.css
diff --git a/modules/search/search.module b/modules/search/search.module
index b5a135c2b..a66f1b96a 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -98,13 +98,6 @@ function search_help($path, $arg) {
}
/**
- * Implements hook_init().
- */
-function search_init() {
- drupal_add_css(drupal_get_path('module', 'search') . '/search.css', array('preprocess' => TRUE));
-}
-
-/**
* Implements hook_theme().
*/
function search_theme() {
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 0f44bea89..b23e8e53c 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -581,6 +581,27 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
}
/**
+ * Test that stylesheets in module .info files are loaded.
+ */
+ function testModuleInfo() {
+ $this->drupalGet('');
+
+ // Verify common_test.css in a STYLE media="all" tag.
+ $elements = $this->xpath('//style[@media=:media and contains(text(), :filename)]', array(
+ ':media' => 'all',
+ ':filename' => 'tests/common_test.css',
+ ));
+ $this->assertTrue(count($elements), "Stylesheet with media 'all' in module .info file found.");
+
+ // Verify common_test.print.css in a STYLE media="print" tag.
+ $elements = $this->xpath('//style[@media=:media and contains(text(), :filename)]', array(
+ ':media' => 'print',
+ ':filename' => 'tests/common_test.print.css',
+ ));
+ $this->assertTrue(count($elements), "Stylesheet with media 'print' in module .info file found.");
+ }
+
+ /**
* Tests adding a file stylesheet.
*/
function testAddFile() {
diff --git a/modules/simpletest/tests/common_test.info b/modules/simpletest/tests/common_test.info
index 81a15472a..7b27416ae 100644
--- a/modules/simpletest/tests/common_test.info
+++ b/modules/simpletest/tests/common_test.info
@@ -5,4 +5,6 @@ package = Testing
version = VERSION
core = 7.x
files[] = common_test.module
+stylesheets[all][] = common_test.css
+stylesheets[print][] = common_test.print.css
hidden = TRUE
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 276d39f8b..ebd4f20ed 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -1441,9 +1441,10 @@ function hook_boot() {
* used to set up global parameters which are needed later in the request.
* when this hook is called, all modules are already loaded in memory.
*
- * For example, this hook is a typical place for modules to add CSS or JS
- * that should be present on every page. This hook is not run on cached
- * pages - though CSS or JS added this way will be present on a cached page.
+ * This hook is not run on cached pages.
+ *
+ * To add CSS or JS that should be present on all pages, modules should not
+ * implement this hook, but declare these files in their .info file.
*/
function hook_init() {
drupal_add_css(drupal_get_path('module', 'book') . '/book.css');
@@ -3955,7 +3956,7 @@ function hook_filetransfer_backends() {
/**
* Control site status before menu dispatching.
*
- * The hook is called after checking whether the site is offline but before
+ * The hook is called after checking whether the site is offline but before
* the current router item is retrieved and executed by
* menu_execute_active_handler(). If the site is in offline mode,
* $menu_site_status is set to MENU_SITE_OFFLINE.
diff --git a/modules/system/system.module b/modules/system/system.module
index 33f232f74..f0cab512c 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1837,7 +1837,6 @@ function system_init() {
drupal_add_css($path . '/system-menus.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
drupal_add_css($path . '/system-messages.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
-
// Ignore slave database servers for this request.
//
// In Drupal's distributed database structure, new data is written to the master
@@ -1859,6 +1858,29 @@ function system_init() {
unset($_SESSION['ignore_slave_server']);
}
}
+
+ // Add CSS/JS files from module .info files.
+ system_add_module_assets();
+}
+
+/**
+ * Adds CSS and JavaScript files declared in module .info files.
+ */
+function system_add_module_assets() {
+ foreach (system_get_info('module') as $module => $info) {
+ if (!empty($info['stylesheets'])) {
+ foreach ($info['stylesheets'] as $media => $stylesheets) {
+ foreach ($stylesheets as $stylesheet) {
+ drupal_add_css($stylesheet, array('media' => $media, 'preprocess' => TRUE));
+ }
+ }
+ }
+ if (!empty($info['scripts'])) {
+ foreach ($info['scripts'] as $script) {
+ drupal_add_js($script, array('preprocess' => TRUE));
+ }
+ }
+ }
}
/**
@@ -2305,6 +2327,15 @@ function _system_rebuild_module_data() {
// Merge in defaults and save.
$modules[$key]->info = $module->info + $defaults;
+ // Prefix stylesheets and scripts with module path.
+ $path = dirname($module->uri);
+ if (isset($module->info['stylesheets'])) {
+ $module->info['stylesheets'] = _system_info_add_path($module->info['stylesheets'], $path);
+ }
+ if (isset($module->info['scripts'])) {
+ $module->info['scripts'] = _system_info_add_path($module->info['scripts'], $path);
+ }
+
// Install profiles are hidden by default, unless explicitly specified
// otherwise in the .info file.
if ($key == $profile && !isset($modules[$key]->info['hidden'])) {
@@ -2396,6 +2427,8 @@ function _system_rebuild_theme_data() {
'features' => _system_default_theme_features(),
'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP,
+ 'stylesheets' => array(),
+ 'scripts' => array(),
);
$sub_themes = array();
@@ -2428,28 +2461,14 @@ function _system_rebuild_theme_data() {
}
}
- // Give the stylesheets proper path information.
- $pathed_stylesheets = array();
- if (isset($themes[$key]->info['stylesheets'])) {
- foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) {
- foreach ($stylesheets as $stylesheet) {
- $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->uri) . '/' . $stylesheet;
- }
- }
- }
- $themes[$key]->info['stylesheets'] = $pathed_stylesheets;
+ // Prefix stylesheets and scripts with module path.
+ $path = dirname($theme->uri);
+ $theme->info['stylesheets'] = _system_info_add_path($theme->info['stylesheets'], $path);
+ $theme->info['scripts'] = _system_info_add_path($theme->info['scripts'], $path);
- // Give the scripts proper path information.
- $scripts = array();
- if (isset($themes[$key]->info['scripts'])) {
- foreach ($themes[$key]->info['scripts'] as $script) {
- $scripts[$script] = dirname($themes[$key]->uri) . '/' . $script;
- }
- }
- $themes[$key]->info['scripts'] = $scripts;
// Give the screenshot proper path information.
if (!empty($themes[$key]->info['screenshot'])) {
- $themes[$key]->info['screenshot'] = dirname($themes[$key]->uri) . '/' . $themes[$key]->info['screenshot'];
+ $themes[$key]->info['screenshot'] = $path . '/' . $themes[$key]->info['screenshot'];
}
}
@@ -2497,6 +2516,41 @@ function system_rebuild_theme_data() {
}
/**
+ * Prefixes all values in an .info file array with a given path.
+ *
+ * This helper function is mainly used to prefix all array values of an .info
+ * file property with a single given path (to the module or theme); e.g., to
+ * prefix all values of the 'stylesheets' or 'scripts' properties with the file
+ * path to the defining module/theme.
+ *
+ * @param $info
+ * A nested array of data of an .info file to be processed.
+ * @param $path
+ * A file path to prepend to each value in $info.
+ *
+ * @return
+ * The $info array with prefixed values.
+ *
+ * @see _system_rebuild_module_data()
+ * @see _system_rebuild_theme_data()
+ */
+function _system_info_add_path($info, $path) {
+ foreach ($info as $key => $value) {
+ // Recurse into nested values until we reach the deepest level.
+ if (is_array($value)) {
+ $info[$key] = _system_info_add_path($info[$key], $path);
+ }
+ // Unset the original value's key and set the new value with prefix, using
+ // the original value as key, so original values can still be looked up.
+ else {
+ unset($info[$key]);
+ $info[$value] = $path . '/' . $value;
+ }
+ }
+ return $info;
+}
+
+/**
* Returns an array of default theme features.
*/
function _system_default_theme_features() {
diff --git a/modules/user/user.info b/modules/user/user.info
index 338d89e78..cfe9c15a8 100644
--- a/modules/user/user.info
+++ b/modules/user/user.info
@@ -12,3 +12,4 @@ files[] = user.test
files[] = user.tokens.inc
required = TRUE
configure = admin/config/people
+stylesheets[all][] = user.css
diff --git a/modules/user/user.module b/modules/user/user.module
index 26335081e..403b42899 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -1799,13 +1799,6 @@ function user_admin_paths() {
}
/**
- * Implements hook_init().
- */
-function user_init() {
- drupal_add_css(drupal_get_path('module', 'user') . '/user.css', array('preprocess' => TRUE));
-}
-
-/**
* Load either a specified or the current user account.
*
* @param $uid
diff --git a/themes/bartik/bartik.info b/themes/bartik/bartik.info
index c300b94c9..689fcc330 100644
--- a/themes/bartik/bartik.info
+++ b/themes/bartik/bartik.info
@@ -12,8 +12,6 @@ stylesheets[all][] = css/style.css
stylesheets[all][] = css/colors.css
stylesheets[print][] = css/print.css
-scripts[] = scripts/search.js
-
regions[header] = Header
regions[help] = Help
regions[page_top] = Page top