Having an issue using \Drupal::service('features.manager')->import() inside a hook_update_N().
Features only imports the first feature, and skips the rest.

I've tried this:

$features = [
  'feature_1',
  'feature_2',
  'feature_3',
  'feature_4',
  'feature_5'
];
\Drupal::service('features.manager')->import($features);

And also this:

\Drupal::service('features.manager')->import(['feature_1']);
\Drupal::service('features.manager')->import(['feature_2']);
\Drupal::service('features.manager')->import(['feature_3']);
\Drupal::service('features.manager')->import(['feature_4']);
\Drupal::service('features.manager')->import(['feature_5']);

Using either of these, only feature_1 gets imported. I’ve tried changing the order, to see if there is something problematic about any of the features, and that’s not the case. Whatever feature I put first, either in the array or the separated out code, gets imported, and the rest are ignored.

No errors in the logs at all.

Comments

wluisi created an issue. See original summary.

gdevan17’s picture

@wluisi any updates on this? I am having the same problem with version 8.x-3.8. ty

gdevan17’s picture

Adding the following two lines before the import declaration fixes the issue:

$assigner = \Drupal::service('features_assigner');
$assigner->assignConfigPackages();

The fix is mentioned in the following Drupal ticket: https://www.drupal.org/project/features/issues/2852248 The ticket also mentions that the fix should no longer be necessary (comment #6) However, the problem does seem to persist in certain environments. Drupal version is 8.6.10

ty

dwkitchen’s picture

Version: 8.x-3.7 » 8.x-3.11
ricksta’s picture

Try a "foreach" loop:

function ..._deploy_update_N() {
  $modules = [
    'module_a',
    'module_b',
  ];
  foreach ($modules as $module) {
    \Drupal::service('features.manager')->import([$module], TRUE);
  }
}