function _drush_pm_find_common_path

8.0.x _drush_pm_find_common_path($project_type, $extensions)
6.x _drush_pm_find_common_path($project_type, $extensions)
7.x _drush_pm_find_common_path($project_type, $extensions)
5.x _drush_pm_find_common_path($project_type, $extensions)
master _drush_pm_find_common_path($project_type, $extensions)

Helper function to find the common path for a list of extensions in the aim to obtain the project name.


$project_type: Type of project we're trying to find. Valid values: module, theme.

$extensions: Array of extension names.

Related topics

1 call to _drush_pm_find_common_path()
drush_get_projects in commands/pm/
Obtain an array of installed projects off the extensions available.


commands/pm/, line 799
The drush Project Manager


function _drush_pm_find_common_path($project_type, $extensions) {
  // Select the first path as the candidate to be the common prefix.
  $extension = array_pop($extensions);
  while (!($path = drupal_get_path($project_type, $extension))) {
    drush_log(dt('Unknown path for !extension !type.', array('!extension' => $extension, '!type' => $project_type)), LogLevel::WARNING);
    $extension = array_pop($extensions);

  // If there's only one extension we are done. Otherwise, we need to find
  // the common prefix for all of them.
  if (count($extensions) > 0) {
    // Iterate over the other projects.
    while ($extension = array_pop($extensions)) {
      $path2 = drupal_get_path($project_type, $extension);
      if (!$path2) {
        drush_log(dt('Unknown path for !extension !type.', array('!extension' => $extension, '!type' => $project_type)), LogLevel::DEBUG);
      // Option 1: same path.
      if ($path == $path2) {
      // Option 2: $path is a prefix of $path2.
      if (strpos($path2, $path) === 0) {
      // Option 3: $path2 is a prefix of $path.
      if (strpos($path, $path2) === 0) {
        $path = $path2;
      // Option 4: no one is a prefix of the other. Find the common
      // prefix by iteratively strip the rigthtmost piece of $path.
      // We will iterate until a prefix is found or path = '.', that on the
      // other hand is a condition theorically impossible to reach.
      do {
        $path = dirname($path);
        if (strpos($path2, $path) === 0) {
      } while ($path != '.');

  return $path;