function LocaleProjectRepository::getAll
Same name and namespace in other branches
- 11.x core/modules/locale/src/LocaleProjectRepository.php \Drupal\locale\LocaleProjectRepository::getAll()
Returns all the project records.
Return value
array An associative array of items successfully returned, indexed by key.
File
-
core/
modules/ locale/ src/ LocaleProjectRepository.php, line 57
Class
- LocaleProjectRepository
- Provides storage and rebuilding of locale project information.
Namespace
Drupal\localeCode
public function getAll() : array {
$cid = 'locale_get_projects';
if ($cached = $this->memoryCache
->get($cid)) {
$projects = $cached->data;
}
else {
$projects = $this->keyValueFactory
->get('locale.project')
->getAll();
if (count($projects) === 0) {
// At least the core project should be in the database, so we build the
// data if none are found.
$projects = $this->buildProjects();
}
else {
$projects = array_map(function (array $project) {
return LocaleTranslatableProject::createFromArray($project);
}, $projects);
}
uksort($projects, function ($a, $b) use (&$projects) {
// 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 retrieved from
// the database.
$sort = (int) $projects[$a]?->getWeight() <=> (int) $projects[$b]?->getWeight();
return $sort ?: strcmp($a, $b);
});
$projects = array_filter($projects, fn($value) => $value !== NULL);
$this->memoryCache
->set($cid, $projects, Cache::PERMANENT);
}
return $projects;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.