This is a small tweak (2 line change) so when retrieving a sub-set of files with the $scope parameter, it acts like a filter.
Here's an example of how this is all connected.
File search patterns defined from the .info/.pinfo file:
; file.extensions[$scope:$group] = .ext
file.extensions[all:styles] = .css
; More advanced file naming patterns.
file.patterns[all:hook_alter] = /^[[:alpha:]][[:alnum:]_]+\.alter\.inc$/
With the above in place, function that are part of the file API will return targeted files. This is how it works right now:
// Scope can be 'all', 'theme', 'plugin' or any theme or plug-in key hosting
// a particular file but it is ultimately decided by the scope defined from
// file.extensions and file.patterns keys within .info/.pinfo. If it is not
// from .info/.pinfo, it will default to the host type. 'theme' for .info
// (theme owned) or 'plugin' for .pinfo (plugin owned).
$scope = 'all';
// Group is a particular bucket the file will reside in also defined from the
// .info/.pinfo file. If it's not set from .info/.pinfo, it will fall into the
// 'general' group.
$group = 'styles';
// This will return the file closest to the current theme. In other words, If
// a child theme is active and both the base theme and sub-theme owns a file
// with the same name, the one within the sub-theme will be returned since it
// is considered an override. If the sub-theme does not hold the file, the one
// from the base theme will be returned.
$path = hex_file_path('colors.css', $group, $scope);
But the $scope has to be called as it is defined from .info/.pinfo. Before the patch, it didn't allow calling of a sub-set if the scope.
// 'theme' was never defined but it is inside the scope of 'all' so it should
// return anything owned by a theme.
$scope = 'theme';
// Same with 'plugin'.
$scope = 'plugin';
// This will return the file owned by the specific host which can be a theme
// or plugin.
$scope = 'hex';
$path = hex_file_path('colors.css', 'styles', $scope);
Defining a very narrow scope from the .info/.pinfo file will limit what the api functions will return. This was always the case and hasn't been changed in this patch.
; Files owned by 'hex'.
file.extensions[hex:scripts] = .js
// The $scope here is 'all' but it will only return files by hexagon because
// the limited scope defined from .info/.pinfo
$path = hex_file_path('script.js', 'scripts', 'all');
Comment | File | Size | Author |
---|---|---|---|
#4 | patch_commit_0e759eb4de8f.patch | 4.26 KB | dvessel |
#3 | patch_commit_9e7b3ce7ce6b.patch | 1.6 KB | dvessel |
#2 | patch_commit_09335fcf2fe6.patch | 1.59 KB | dvessel |
#1 | patch_commit_c1a9efd2a7c6.patch | 729 bytes | dvessel |
Comments
Comment #1
dvessel CreditAttribution: dvessel commentedThe API functions this affects:
Shown here with the default parameters.
hex_path_to_file($name, $group = 'general', $scope = 'all');
hex_path_to_file_multiple($name, $group = 'general', $scope = 'all');
hex_get_files($group, $scope);
hex_list_file_groups($scope = 'all');
Comment #2
dvessel CreditAttribution: dvessel commentedOkay, a little more than 2 lines. Whoops. And I screwed up the commit. Don't 'amend' commits.
Comment #3
dvessel CreditAttribution: dvessel commentedPrevious patch was bad. Prevented overriding completely. Doh!
Comment #4
dvessel CreditAttribution: dvessel commentedUpdated code comments.