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');
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dvessel’s picture

The 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');
dvessel’s picture

Status: Active » Fixed
FileSize
1.59 KB

Okay, a little more than 2 lines. Whoops. And I screwed up the commit. Don't 'amend' commits.

dvessel’s picture

Previous patch was bad. Prevented overriding completely. Doh!

dvessel’s picture

Updated code comments.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.