Problem/Motivation
The namespace assignment plugin is intended to match patterns in short-version configuration names to the short name of a package.
In #2813515: Namespace assignment plugin is still matching incorrect config we tweaked the matching. Specifically, the aim in #2813515 was to prevent configuration with a short name landing_page
from being assigned automatically to a page
package. However, in fixing this edge case, we appear to have broken a main use case: assigning fields by feature short name prefix (e.g., article
).
Custom field names are by default prefixed with field_
. For example, a field name for an article type would be field_article_type
. Since #2813515, this is by default no longer matched and instead assigned to an incorrect feature (core).
Proposed resolution
To solve #2813515, rather than restricting the ways we match, we should instead alter our ordering of package names to match.
Currently we have this code in FeaturesManager::assignConfigByPattern()
:
$config_collection = $this->getConfigCollection();
// Reverse sort by key so that child package will claim items before parent
// package. E.g., event_registration will claim before event.
krsort($config_collection);
foreach ($patterns as $pattern => $machine_name) {
This is simply wrong. To ensure event_registration
claimed items before event
, we would need to sort $patterns
, not the items we're matching against.
But merely sorting reverse alphabetical isn't sufficient. From #2813515:
Lightning has a content type called "landing_page". In a default installation, Features marks the Entity View Display node.landing_page.full from Lightning Layout as "Moved" to the "Page" default package.
So what we want is: both registration_event
and event_registration
are matched before event
.
To do so, we can use an array sorting function that measures the number of segments in a package short name (substr_count($pattern, '_')
), putting higher counts first in the array.
Work completed:
- Sort package short name patterns by number of segments (
registration_event
has two,event
has one) so that more specific patterns are matched first. - Change the regular expression we're matching against to use the same tokens at each end. Currently it's
'/(\.|^)' . $pattern . '(\.|-|_|$)/'
. Change it to('/(\.|-|_|^)' . $pattern . '(\.|-|_|$)/'
.
Remaining tasks
- Update relevant tests to test declare multiple packages with the names we're testing against, e.g.,
registration_event
,event_registration
,event
.
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#10 | features-namespace-patterns-2832184-10.patch | 5.58 KB | nedjo |
Comments
Comment #2
nedjoComment #3
nedjoComment #4
nedjoI had a seemingly unrelated test failure locally. See what the testbot does.
Comment #7
nedjoAn exception for
field_
is the wrong approach here. Updating summary and setting back to active.Comment #8
nedjoComment #9
nedjoUpdated patch. Updates to tests still needed so setting to needs work.
Comment #10
nedjoExtend tests to cover full range of matching patterns.
Comment #13
nedjoRevised tests passing, applied. (Test failure due to #2833258: Test failure from core change.)