function search_requirements

Same name in other branches
  1. 9 core/modules/search/search.install \search_requirements()
  2. 10 core/modules/search/search.install \search_requirements()
  3. 11.x core/modules/search/search.install \search_requirements()

Implements hook_requirements().

For the Status Report, return information about search index status.

File

core/modules/search/search.install, line 131

Code

function search_requirements($phase) {
    $requirements = [];
    if ($phase == 'runtime') {
        $remaining = 0;
        $total = 0;
        $search_page_repository = \Drupal::service('search.search_page_repository');
        foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
            $status = $entity->getPlugin()
                ->indexStatus();
            $remaining += $status['remaining'];
            $total += $status['total'];
        }
        $done = $total - $remaining;
        // Use floor() to calculate the percentage, so if it is not quite 100%, it
        // will show as 99%, to indicate "almost done".
        $percent = $total > 0 ? floor(100 * $done / $total) : 100;
        $requirements['search_status'] = [
            'title' => t('Search index progress'),
            'value' => t('@percent% (@remaining remaining)', [
                '@percent' => $percent,
                '@remaining' => $remaining,
            ]),
            'severity' => REQUIREMENT_INFO,
        ];
    }
    return $requirements;
}

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