Closed (fixed)
Project:
Hexagon
Version:
7.x-2.0-alpha4
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Aug 2011 at 19:33 UTC
Updated:
16 Aug 2011 at 19:41 UTC
Jump to comment: Most recent file
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 commented