ExtensionDiscovery::sort

protected ExtensionDiscovery::sort(array $all_files, array $weights)

Sorts the discovered extensions.

Parameters

\Drupal\Core\Extension\Extension[] $all_files.: The list of all extensions.

array $weights: An array of weights, keyed by originating directory.

Return value

\Drupal\Core\Extension\Extension[] The sorted list of extensions.

File

core/lib/Drupal/Core/Extension/ExtensionDiscovery.php, line 325

Class

ExtensionDiscovery
Discovers available extensions in the filesystem.

Namespace

Drupal\Core\Extension

Code

protected function sort(array $all_files, array $weights) {
  $origins = array();
  $profiles = array();
  foreach ($all_files as $key => $file) {
    // If the extension does not belong to a profile, just apply the weight
    // of the originating directory.
    if (strpos($file->subpath, 'profiles') !== 0) {
      $origins[$key] = $weights[$file->origin];
      $profiles[$key] = NULL;
    }
    // If the extension belongs to a profile but no profile directories are
    // defined, then we are scanning for installation profiles themselves.
    // In this case, profiles are sorted by origin only.
    elseif (empty($this->profileDirectories)) {
      $origins[$key] = static::ORIGIN_PROFILE;
      $profiles[$key] = NULL;
    }
    else {
      // Apply the weight of the originating profile directory.
      foreach ($this->profileDirectories as $weight => $profile_path) {
        if (strpos($file->getPath(), $profile_path) === 0) {
          $origins[$key] = static::ORIGIN_PROFILE;
          $profiles[$key] = $weight;
          continue 2;
        }
      }
    }
  }
  // Now sort the extensions by origin and installation profile(s).
  // The result of this multisort can be depicted like the following matrix,
  // whereas the first integer is the weight of the originating directory and
  // the second is the weight of the originating installation profile:
  // 0   core/modules/node/node.module
  // 1 0 profiles/parent_profile/modules/parent_module/parent_module.module
  // 1 1 core/profiles/testing/modules/compatible_test/compatible_test.module
  // 2   sites/all/modules/common/common.module
  // 3   modules/devel/devel.module
  // 4   sites/default/modules/custom/custom.module
  array_multisort($origins, SORT_ASC, $profiles, SORT_ASC, $all_files);

  return $all_files;
}
doc_Drupal
2016-10-29 09:09:44
Comments
Leave a Comment

Please login to continue.