class SearchRequirements

Requirements for the Search module.

Hierarchy

Expanded class hierarchy of SearchRequirements

File

core/modules/search/src/Hook/SearchRequirements.php, line 15

Namespace

Drupal\search\Hook
View source
class SearchRequirements {
  use StringTranslationTrait;
  public function __construct(protected readonly SearchPageRepositoryInterface $searchPageRepository) {
  }
  
  /**
   * Implements hook_runtime_requirements().
   *
   * For the Status Report, return information about search index status.
   */
  public function runtime() : array {
    $requirements = [];
    $remaining = 0;
    $total = 0;
    foreach ($this->searchPageRepository
      ->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' => $this->t('Search index progress'),
      'value' => $this->t('@percent% (@remaining remaining)', [
        '@percent' => $percent,
        '@remaining' => $remaining,
      ]),
      'severity' => RequirementSeverity::Info,
    ];
    return $requirements;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
SearchRequirements::runtime public function Implements hook_runtime_requirements().
SearchRequirements::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

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