function _update_requirement_check

Same name in other branches
  1. 7.x modules/update/update.install \_update_requirement_check()
  2. 9 core/modules/update/update.install \_update_requirement_check()
  3. 8.9.x core/modules/update/update.install \_update_requirement_check()
  4. 11.x core/modules/update/update.install \_update_requirement_check()

Fills in the requirements array.

This is shared for both core and contrib to generate the right elements in the array for hook_requirements().

Parameters

$project: Array of information about the project we're testing as returned by update_calculate_project_data().

$type: What kind of project this is ('core' or 'contrib').

Return value

array An array to be included in the nested $requirements array.

See also

hook_requirements()

update_requirements()

update_calculate_project_data()

1 call to _update_requirement_check()
update_requirements in core/modules/update/update.install
Implements hook_requirements().

File

core/modules/update/update.install, line 111

Code

function _update_requirement_check($project, $type) {
    $requirement = [];
    if ($type == 'core') {
        $requirement['title'] = t('Drupal core update status');
    }
    else {
        $requirement['title'] = t('Module and theme update status');
    }
    $status = $project['status'];
    if ($status != UpdateManagerInterface::CURRENT) {
        $requirement['reason'] = $status;
        $requirement['severity'] = REQUIREMENT_ERROR;
        // When updates are available, append the available updates link to the
        // message from _update_message_text(), and format the two translated
        // strings together in a single paragraph.
        $requirement['description'][] = [
            '#markup' => _update_message_text($type, $status),
        ];
        if (!in_array($status, [
            UpdateFetcherInterface::UNKNOWN,
            UpdateFetcherInterface::NOT_CHECKED,
            UpdateFetcherInterface::NOT_FETCHED,
            UpdateFetcherInterface::FETCH_PENDING,
        ])) {
            if (_update_manager_access()) {
                $requirement['description'][] = [
                    '#prefix' => ' ',
                    '#markup' => t('See the <a href=":available_updates">available updates</a> page for more information and to update your software.', [
                        ':available_updates' => Url::fromRoute('update.report_update')->toString(),
                    ]),
                ];
            }
            else {
                $requirement['description'][] = [
                    '#prefix' => ' ',
                    '#markup' => t('See the <a href=":available_updates">available updates</a> page for more information.', [
                        ':available_updates' => Url::fromRoute('update.status')->toString(),
                    ]),
                ];
            }
        }
    }
    switch ($status) {
        case UpdateManagerInterface::NOT_SECURE:
            $requirement_label = t('Not secure!');
            break;
        case UpdateManagerInterface::REVOKED:
            $requirement_label = t('Revoked!');
            break;
        case UpdateManagerInterface::NOT_SUPPORTED:
            $requirement_label = t('Unsupported release');
            break;
        case UpdateManagerInterface::NOT_CURRENT:
            $requirement_label = t('Out of date');
            $requirement['severity'] = REQUIREMENT_WARNING;
            break;
        case UpdateFetcherInterface::UNKNOWN:
        case UpdateFetcherInterface::NOT_CHECKED:
        case UpdateFetcherInterface::NOT_FETCHED:
        case UpdateFetcherInterface::FETCH_PENDING:
            $requirement_label = $project['reason'] ?? t('Can not determine status');
            $requirement['severity'] = REQUIREMENT_WARNING;
            break;
        default:
            $requirement_label = t('Up to date');
    }
    if ($status != UpdateManagerInterface::CURRENT && $type == 'core' && isset($project['recommended'])) {
        $requirement_label .= ' ' . t('(version @version available)', [
            '@version' => $project['recommended'],
        ]);
    }
    $requirement['value'] = Link::fromTextAndUrl($requirement_label, Url::fromRoute(_update_manager_access() ? 'update.report_update' : 'update.status'))->toString();
    return $requirement;
}

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