Problem/Motivation

When bringing up the feature edit form for a feature that has missing configuration (configuration provided by the feature but not present in the active storage), the following error results:

Fatal error: Call to a member function getPackage() on a non-object in /path/to/site/modules/features/src/FeaturesManager.php on line 567

If this error is addressed, a subsequent error occurs:

Fatal error: Call to a member function getType() on a non-object in /path/to/site/modules/features/modules/features_ui/src/Form/FeaturesEditForm.php on line 539

Both errors result from code that loads the configuration collection (which lists items in the active configuration storage) and then attempts to load from the collection an item that is present in an extension but not on the site.

This specific error results from #2595265: Remodel configuration items in FeaturesManager::configCollection as objects, but the problem presumably predates that change.

Proposed resolution

Test whether the item exists in the configuration collection before calling its methods.

Remaining tasks

Needs tests.

User interface changes

API changes

Data model changes

Comments

nedjo created an issue. See original summary.

nedjo’s picture

Title: Error when configuration missing from feature » Error on feature edit page when configuration missing from feature
nedjo’s picture

Issue summary: View changes
Status: Active » Needs work
Issue tags: +Needs tests
StatusFileSize
new2.36 KB

Patch attached. Setting to "Needs work" because this should have an accompanying test.

  • nedjo committed 2713595 on 8.x-3.x
    Issue #2624542 by nedjo: Error on feature edit page when configuration...
nedjo’s picture

I've applied this fix in order to be able to post a new alpha release. Leaving at needs work pending tests.

kolier’s picture

Add one more line to fix this issue in FeaturesEditForm.php

    // Make a map of any config specifically excluded and/or required.
    foreach (array('excluded', 'required') as $constraint) {
      $this->{$constraint} = array();
      $info = !empty($this->package->getFeaturesInfo()[$constraint]) ? $this->package->getFeaturesInfo()[$constraint] : array();
      foreach ($info as $item_name) {
        if (!in_array($item_name, $config)) continue;
        $item = $config[$item_name];
        $this->{$constraint}[$item->getType()][$item->getShortName()] = $item->getLabel();
      }
    }
rjarteta’s picture

StatusFileSize
new721 bytes

Adding the patch suggested by @koiler since the code works properly.
Please review PHPCS

mpotter’s picture

Status: Needs work » Needs review
StatusFileSize
new5.83 KB

Actually, the patch in #7 isn't correct. You don't test if $item_name is in the $config array since it's a key. You use !isset. Here is a correct patch.

(Also, Drupal coding standard doesn't allow "continue" on the same line like that I don't believe)

Status: Needs review » Needs work

The last submitted patch, 8: features-missing-2624542-8.patch, failed testing.

mpotter’s picture

Status: Needs work » Needs review
StatusFileSize
new742 bytes

Ack, sorry, that got another issue mixed in. Here is the correct patch.

nedjo’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

The last submitted patch, 3: features-missing-2624542-3.patch, failed testing.

The last submitted patch, 7: features-missing-2624542-7.patch, failed testing.

mpotter’s picture

@nedjo: Do we know what is causing all the patches to fail testing? How do we even see the test results in D8 these days?

  • mpotter committed 6de80fb on 8.x-3.x
    Issue #2624542 by mpotter, nedjo, panche: Error on feature edit page...
mpotter’s picture

Status: Reviewed & tested by the community » Fixed

OK, committed to 6de80fb

Status: Fixed » Closed (fixed)

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