function LocaleProjectStorage::getAll

Same name and namespace in other branches
  1. 9 core/modules/locale/src/LocaleProjectStorage.php \Drupal\locale\LocaleProjectStorage::getAll()
  2. 8.9.x core/modules/locale/src/LocaleProjectStorage.php \Drupal\locale\LocaleProjectStorage::getAll()
  3. 10 core/modules/locale/src/LocaleProjectStorage.php \Drupal\locale\LocaleProjectStorage::getAll()
1 call to LocaleProjectStorage::getAll()
LocaleProjectStorage::countProjects in core/modules/locale/src/LocaleProjectStorage.php

File

core/modules/locale/src/LocaleProjectStorage.php, line 169

Class

LocaleProjectStorage
Provides the locale project storage system using a key value store.

Namespace

Drupal\locale

Code

public function getAll() {
    if (!$this->all) {
        $this->cache = $this->keyValueStore
            ->getAll();
        $this->all = TRUE;
    }
    if (!$this->sorted) {
        // Work around PHP 8.3.0 - 8.3.3 bug by assigning $this->cache to a local
        // variable, see https://github.com/php/php-src/pull/13285.
        $cache = $this->cache;
        uksort($this->cache, function ($a, $b) use ($cache) {
            // Sort by weight, if available, and then by key. This allows locale
            // projects to set a weight, if required, and keeps the order consistent
            // regardless of whether the list is built from code or retrieve from
            // the database.
            $sort = (int) ($cache[$a]['weight'] ?? 0) <=> (int) ($cache[$b]['weight'] ?? 0);
            return $sort ?: strcmp($a, $b);
        });
        $this->sorted = TRUE;
    }
    // Remove any NULL values as these are not valid projects.
    return array_filter($this->cache, fn($value) => $value !== NULL);
}

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