function Updater::findInfoFile

Same name in other branches
  1. 7.x includes/updater.inc \Updater::findInfoFile()
  2. 8.9.x core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::findInfoFile()
  3. 10 core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::findInfoFile()
  4. 11.x core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::findInfoFile()

Determines what the most important (or only) info file is in a directory.

Since there is no enforcement of which info file is the project's "main" info file, this will get one with the same name as the directory, or the first one it finds. Not ideal, but needs a larger solution.

Parameters

string $directory: Directory to search in.

Return value

string Path to the info file.

2 calls to Updater::findInfoFile()
Updater::getExtensionInfo in core/lib/Drupal/Core/Updater/Updater.php
Get Extension information from directory.
Updater::getProjectTitle in core/lib/Drupal/Core/Updater/Updater.php
Returns the project name from a Drupal info file.

File

core/lib/Drupal/Core/Updater/Updater.php, line 118

Class

Updater
Defines the base class for Updaters used in Drupal.

Namespace

Drupal\Core\Updater

Code

public static function findInfoFile($directory) {
    
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $info_files = [];
    if (is_dir($directory)) {
        $info_files = $file_system->scanDirectory($directory, '/.*\\.info.yml$/');
    }
    if (!$info_files) {
        return FALSE;
    }
    foreach ($info_files as $info_file) {
        if (mb_substr($info_file->filename, 0, -9) == $file_system->basename($directory)) {
            // Info file Has the same name as the directory, return it.
            return $info_file->uri;
        }
    }
    // Otherwise, return the first one.
    $info_file = array_shift($info_files);
    return $info_file->uri;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.