Problem/Motivation

When running drush fr feature_foo, warnings are emitted, like

[warning] Undefined array key 1 FeaturesCommands.php:728

Steps to reproduce

  • Create a feature called feature_foo in a bundle called bar.
  • Run drush fr feature_foo
  • Observe the above-mentioned warning

Data is actually correct in spite of the warning, because $component is set to empty, and handled as such anyway.

Proposed resolution

Avoid the warning by appending, probably by appending an extra ":" at the end of the featureString.

Remaining tasks

Do it.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork features-3202711

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fgm created an issue. See original summary.

fgm’s picture

Status: Active » Needs review

Setting CNR.

jrockowitz’s picture

The solution works but it took me a second to understanding it.

+      // Make sure there will actually be a component before exploding.
+      list($module, $component) = explode(':', "$featureString:");

@see https://stackoverflow.com/questions/2867310/php-explode-and-set-to-empty...

Nice trick to handle the potential Notice, and an empty string rather than a null – Mark Baker - May 19

I think the empty string instead of null for $component is fine.

The online alternative I can think of allow $component to be NULL is...

$values = explode(':', $featureString);
$module = $values[0];
$component = $values[1] ?? NULL;

Here is my sandbox for playing with the other solutions.
https://onlinephp.io/c/d10ee

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community
Dave Reid’s picture

Coming to this because we started seeing this happening on our Pantheon deployments:

terminus drush sitename.dev -- features:import:all --yes
Warning: ] Undefined array key "yes" FeaturesCommands.php:722
Warning: ] Undefined array key 1 FeaturesCommands.php:728
Warning: ] Undefined array key 1 FeaturesCommands.php:728

nedjo made their first commit to this issue’s fork.

  • nedjo committed 2081697a on 8.x-3.x authored by fgm
    Issue #3202711 by fgm: avoid warning on name during import
    

  • nedjo committed 3e41020f on 5.0.x authored by fgm
    Issue #3202711 by fgm: avoid warning on name during import
    
nedjo’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks!

Status: Fixed » Closed (fixed)

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

rwam’s picture

Hi @nedjo,

any chance to see a minor release in the next time? Because 8.x-3.12 was released two years ago and I'd like to see some fixes in a new version.

Thanks & bye
Ralf

matthand’s picture

Features Version 8.x-3.13 was just released and includes this fix. Thank you for your contribution.