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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nedjo created an issue. See original summary.

nedjo’s picture

nedjo’s picture

Issue summary: View changes
nedjo’s picture

I had a seemingly unrelated test failure locally. See what the testbot does.

The last submitted patch, 4: features-namespace-field-2832184-4-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: features-namespace-field-2832184-4.patch, failed testing.

nedjo’s picture

Issue summary: View changes
Status: Needs work » Active

An exception for field_ is the wrong approach here. Updating summary and setting back to active.

nedjo’s picture

Issue summary: View changes
nedjo’s picture

Updated patch. Updates to tests still needed so setting to needs work.

nedjo’s picture

Status: Needs work » Needs review
FileSize
5.58 KB

Extend tests to cover full range of matching patterns.

Status: Needs review » Needs work

The last submitted patch, 10: features-namespace-patterns-2832184-10.patch, failed testing.

  • nedjo committed 07973b5 on 8.x-3.x
    Issue #2832184 by nedjo: Namespace assignment method not matching field...
nedjo’s picture

Status: Needs work » Fixed

Revised tests passing, applied. (Test failure due to #2833258: Test failure from core change.)

Status: Fixed » Closed (fixed)

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