function ModuleDependencyMessageTrait::checkDependencyMessage

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php \Drupal\Core\Extension\ModuleDependencyMessageTrait::checkDependencyMessage()
  2. 8.9.x core/modules/system/src/ModuleDependencyMessageTrait.php \Drupal\system\ModuleDependencyMessageTrait::checkDependencyMessage()
  3. 10 core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php \Drupal\Core\Extension\ModuleDependencyMessageTrait::checkDependencyMessage()

Provides messages for missing modules or incompatible dependencies.

Parameters

array $modules: The list of existing modules.

string $dependency: The module dependency to check.

\Drupal\Core\Extension\Dependency $dependency_object: Dependency object used for comparing version requirement data.

Return value

string|null NULL if compatible, otherwise a string describing the incompatibility.

3 calls to ModuleDependencyMessageTrait::checkDependencyMessage()
ModulesListForm::buildRow in core/modules/system/src/Form/ModulesListForm.php
Builds a table row for the system modules page.
SystemController::themesPage in core/modules/system/src/Controller/SystemController.php
Returns a theme listing which excludes obsolete themes.
ThemeInstaller::install in core/lib/Drupal/Core/Extension/ThemeInstaller.php
Installs a given list of themes.

File

core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php, line 27

Class

ModuleDependencyMessageTrait
Messages for missing or incompatible dependencies on modules.

Namespace

Drupal\Core\Extension

Code

public function checkDependencyMessage(array $modules, $dependency, Dependency $dependency_object) {
    if (!isset($modules[$dependency])) {
        return $this->t('@module_name (<span class="admin-missing">missing</span>)', [
            '@module_name' => $dependency,
        ]);
    }
    else {
        $module_name = $modules[$dependency]->info['name'];
        // Check if the module is compatible with the installed version of core.
        if ($modules[$dependency]->info['core_incompatible']) {
            return $this->t('@module_name (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
                '@module_name' => $module_name,
            ]);
        }
        // Check if the module is incompatible with the dependency constraints.
        // Remove CORE_COMPATIBILITY- only from the start of the string.
        $version = preg_replace('/^(' . \Drupal::CORE_COMPATIBILITY . '\\-)/', '', $modules[$dependency]->info['version'] ?? '');
        if (!$dependency_object->isCompatible($version)) {
            $constraint_string = $dependency_object->getConstraintString();
            return $this->t('@module_name (<span class="admin-missing">incompatible with</span> version @version)', [
                '@module_name' => "{$module_name} ({$constraint_string})",
                '@version' => $modules[$dependency]->info['version'] ?? '* ? *',
            ]);
        }
    }
}

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