function ProjectInfo::getInstalledVersion

Returns the installed project version, according to the Update module.

Return value

string|null The installed project version as known to the Update module or NULL if the project information is not available.

1 call to ProjectInfo::getInstalledVersion()
ProjectInfo::getInstallableReleases in core/modules/package_manager/src/ProjectInfo.php
Gets all project releases to which the site can update.

File

core/modules/package_manager/src/ProjectInfo.php, line 145

Class

ProjectInfo
Defines a class for retrieving project information from Update module.

Namespace

Drupal\package_manager

Code

public function getInstalledVersion() : ?string {
    $project_data = $this->getProjectInfo();
    if ($project_data && array_key_exists('existing_version', $project_data)) {
        $existing_version = $project_data['existing_version'];
        // Treat an unknown version the same as a project whose project
        // information is not available, so return NULL.
        // @see \update_process_project_info()
        if ($existing_version instanceof TranslatableMarkup && $existing_version->getUntranslatedString() === 'Unknown') {
            return NULL;
        }
        // TRICKY: Since this is relying on data coming from
        // \Drupal\update\UpdateManager::getProjects(), we cannot be certain that
        // we are actually receiving strings.
        // @see \Drupal\update\UpdateManager::getProjects()
        if (!is_string($existing_version)) {
            return NULL;
        }
        return $existing_version;
    }
    return NULL;
}

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