function LocaleProjectRepository::buildProjects
Builds a list of projects and stores the result in the database.
Only the properties required by Locale module are included, and additional (custom) modules and translation server data is added.
Return value
array<string, \Drupal\locale\LocaleTranslatableProject> Array of project instances.
1 call to LocaleProjectRepository::buildProjects()
- LocaleProjectRepository::getAll in core/
modules/ locale/ src/ LocaleProjectRepository.php - Returns all the project records.
File
-
core/
modules/ locale/ src/ LocaleProjectRepository.php, line 136
Class
- LocaleProjectRepository
- Provides storage and rebuilding of locale project information.
Namespace
Drupal\localeCode
public function buildProjects() : array {
// Get the project list based on .info.yml files.
$projects = $this->getProjectList();
$existing_projects = $this->keyValueFactory
->get('locale.project')
->getAll();
$pattern = $this->configFactory
->get('locale.settings')
->get('translation.default_server_pattern') ?: \Drupal::TRANSLATION_DEFAULT_SERVER_PATTERN;
$refreshed_projects = [];
foreach ($projects as $name => $data) {
unset($existing_projects[$name]);
$data['info']['version'] ??= '';
// For dev releases, remove the '-dev' part and trust the translation
// server to fall back to the latest stable release for that branch.
if (str_ends_with($data['info']['version'], '-dev')) {
if (preg_match("/^(\\d+\\.x-\\d+\\.).*\$/", $data['info']['version'], $matches)) {
// Example matches: "8.x-1.x-dev", "8.x-1.0-alpha1+5-dev => 8.x-1.x".
$data['info']['version'] = $matches[1] . 'x';
}
elseif (preg_match("/^(\\d+\\.\\d+\\.).*\$/", $data['info']['version'], $matches)) {
// Example match: 8.0.0-dev => 8.0.x (Drupal core)
$data['info']['version'] = $matches[1] . 'x';
}
}
$refreshed_projects[$name] = new LocaleTranslatableProject(name: $name, type: $data['project_type'], core: $data['core'] ?? 'all', version: $data['info']['version'], server_pattern: !empty($data['info']['interface translation server pattern']) ? $data['info']['interface translation server pattern'] : $pattern, info: $data['info'] ?? [], status: TRUE);
$this->set($refreshed_projects[$name]);
}
if (count($existing_projects)) {
// Mark all remaining projects as disabled and store new project data.
foreach ($existing_projects as $name => $data) {
$existing_projects[$name] = LocaleTranslatableProject::createFromArray($data)->setStatus(FALSE);
$this->set($existing_projects[$name]);
}
}
return $refreshed_projects;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.