You are here

function social_features_import in Open Social 8.6

Same name and namespace in other branches
  1. 8 social.profile \social_features_import()
  2. 8.2 social.profile \social_features_import()
  3. 8.3 social.profile \social_features_import()
  4. 8.4 social.profile \social_features_import()
  5. 8.5 social.profile \social_features_import()
  6. 8.7 social.profile \social_features_import()

Imports module config into the active store.

See also

drush_features_import()

1 call to social_features_import()
_social_finalise_batch in ./social.profile
Implements callback_batch_operation().

File

./social.profile, line 540
Enables modules and site configuration for a social site installation.

Code

function social_features_import($args) {

  /** @var \Drupal\features\FeaturesManagerInterface $manager */
  $manager = \Drupal::service('features.manager');

  /** @var \Drupal\config_update\ConfigRevertInterface $config_revert */
  $config_revert = \Drupal::service('features.config_update');

  // Parse list of arguments.
  $modules = [];
  foreach ($args as $arg) {
    $arg = explode(':', $arg);
    $module = array_shift($arg);
    $component = array_shift($arg);
    if (isset($module)) {
      if (empty($component)) {

        // If we received just a feature name, this means that we need all of
        // its components.
        $modules[$module] = TRUE;
      }
      elseif ($modules[$module] !== TRUE) {
        if (!isset($modules[$module])) {
          $modules[$module] = [];
        }
        $modules[$module][] = $component;
      }
    }
  }

  // Process modules.
  foreach ($modules as $module => $components_needed) {

    /** @var \Drupal\features\Package $feature */
    $feature = $manager
      ->loadPackage($module, TRUE);
    if (empty($feature)) {
      return;
    }
    if ($feature
      ->getStatus() != FeaturesManagerInterface::STATUS_INSTALLED) {
      return;
    }

    // Only revert components that are detected to be Overridden.
    $components = $manager
      ->detectOverrides($feature);
    $missing = $manager
      ->reorderMissing($manager
      ->detectMissing($feature));

    // Be sure to import missing components first.
    $components = array_merge($missing, $components);
    if (!empty($components_needed) && is_array($components_needed)) {
      $components = array_intersect($components, $components_needed);
    }
    if (!empty($components)) {
      $config = $manager
        ->getConfigCollection();
      foreach ($components as $component) {
        if (!isset($config[$component])) {

          // Import missing component.

          /** @var array $item */
          $item = $manager
            ->getConfigType($component);
          $type = ConfigurationItem::fromConfigStringToConfigType($item['type']);
          $config_revert
            ->import($type, $item['name_short']);
        }
        else {

          // Revert existing component.

          /** @var \Drupal\features\ConfigurationItem $item */
          $item = $config[$component];
          $type = ConfigurationItem::fromConfigStringToConfigType($item
            ->getType());
          $config_revert
            ->revert($type, $item
            ->getShortName());
        }
      }
    }
  }
}