Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This bit was added. Very useful for debugging.
/**
* Returns an array of file paths based on a pattern.
*
* @see hex_file_path() for more info.
*
* @param $pattern
* A regex pattern that will be compared to each namespace for a given
* $scope.
* @param $scope
* Can be 'all', 'theme' or 'plugin'. It can also be a specific theme or
* plug-in name, whichever owns or "hosts" the file. File discovery depends
* on how the scope was defined from the .info/.pinfo file. When this
* function is called, it can be any sub-set of the defined scope. It can
* also be a super-set but the returned file paths will always be limited by
* the scope set from .info/.pinfo.
*/
function hex_file_path_pattern($pattern, $scope = 'all') {
$files = hex_cache('files')->data;
$list = array();
if (isset($files[$scope])) {
foreach (preg_grep($pattern, array_keys($files[$scope])) as $namespace) {
$list = array_merge($list, $files[$scope][$namespace]);
}
}
return $list;
}
This .info entry will produce an internal list of all files matching this extension and assign it to the "styles" name space:
file.extensions[styles] = .css
Example calls:
// Must pass a valid regex pattern.
$all_styles = hex_file_path_pattern(":styles:");
// Will output:
array(
0 => string 'sites/all/themes/THEME/colors.css',
1 => string 'sites/all/themes/THEME/layout.css',
2 => string 'sites/all/themes/THEME/layout-rtl.css',
3 => string 'sites/all/themes/THEME/override/foo.css',
4 => string 'sites/all/themes/THEME/override/foo-rtl.css',
5 => string 'sites/all/themes/THEME/override/bar.css',
6 => string 'sites/all/themes/THEME/override/bar-rtl.css',
//etc...
);
$rtl_styles = hex_file_path_pattern(":styles/.+-rtl:");
// Will output:
array(
1 => string 'sites/all/themes/THEME/layout-rtl.css',
2 => string 'sites/all/themes/THEME/override/foo-rtl.css',
3 => string 'sites/all/themes/THEME/override/bar-rtl.css',
//etc...
);
It can be used in a finished theme but most calls should be done through hex_file_path()
and hex_file_path_multiple()
.
Comment | File | Size | Author |
---|---|---|---|
#1 | patch_commit_ef83b9e3dc72.patch | 1.4 KB | dvessel |
Comments
Comment #1
dvessel CreditAttribution: dvessel commented