function install_profile_info in Drupal 9
Same name and namespace in other branches
- 8 core/includes/install.inc \install_profile_info()
- 7 includes/install.inc \install_profile_info()
Retrieves information about an installation profile from its .info.yml file.
The information stored in a profile .info.yml file is similar to that stored in a normal Drupal module .info.yml file. For example:
- name: The real name of the installation profile for display purposes.
- description: A brief description of the profile.
- dependencies: An array of shortnames of other modules that this install profile requires.
- install: An array of shortname of other modules to install that are not required by this install profile.
Additional, less commonly-used information that can appear in a profile.info.yml file but not in a normal Drupal module .info.yml file includes:
- distribution: Existence of this key denotes that the installation profile
is intended to be the only eligible choice in a distribution and will be
auto-selected during installation, whereas the installation profile
selection screen will be skipped. If more than one distribution profile is
found then the first one discovered will be selected.
The following subproperties may be set:
- name: The name of the distribution that is being installed, to be shown throughout the installation process. If omitted, drupal_install_profile_distribution_name() defaults to 'Drupal'.
- install: Optional parameters to override the installer:
- theme: The machine name of a theme to use in the installer instead of Drupal's default installer theme.
- finish_url: A destination to visit after the installation of the distribution is finished
Note that this function does an expensive file system scan to get info file information for dependencies. If you only need information from the info file itself, use \Drupal::service('extension.list.profile')->getExtensionInfo().
Example of .info.yml file:
name: Minimal
description: Start fresh, with only a few modules enabled.
install:
- block
- dblog
Parameters
$profile: Name of profile.
$langcode: Language code (if any).
Return value
The info array.
6 calls to install_profile_info()
- drupal_check_profile in core/
includes/ install.inc - Checks an installation profile's requirements.
- InstallerDependenciesResolutionTest::testDependenciesResolution in core/
modules/ system/ tests/ src/ Kernel/ Installer/ InstallerDependenciesResolutionTest.php - Verifies that the exception message in the profile step is correct.
- InstallerLanguageTest::testInstallerTranslationCache in core/
tests/ Drupal/ KernelTests/ Core/ Installer/ InstallerLanguageTest.php - Tests profile info caching in non-English languages.
- install_load_profile in core/
includes/ install.core.inc - Loads information about the chosen profile during installation.
- SelectProfileForm::buildForm in core/
lib/ Drupal/ Core/ Installer/ Form/ SelectProfileForm.php - Form constructor.
File
- core/
includes/ install.inc, line 1102 - API functions for installing modules and themes.
Code
function install_profile_info($profile, $langcode = 'en') {
static $cache = [];
if (!isset($cache[$profile][$langcode])) {
// Set defaults for module info.
$defaults = [
'dependencies' => [],
'install' => [],
'themes' => [
'stark',
],
'description' => '',
'version' => NULL,
'hidden' => FALSE,
'php' => \Drupal::MINIMUM_PHP,
'config_install_path' => NULL,
];
$profile_path = \Drupal::service('extension.list.profile')
->getPath($profile);
$info = \Drupal::service('info_parser')
->parse("{$profile_path}/{$profile}.info.yml");
$info += $defaults;
$dependency_name_function = function ($dependency) {
return Dependency::createFromString($dependency)
->getName();
};
// Convert dependencies in [project:module] format.
$info['dependencies'] = array_map($dependency_name_function, $info['dependencies']);
// Convert install key in [project:module] format.
$info['install'] = array_map($dependency_name_function, $info['install']);
// drupal_required_modules() includes the current profile as a dependency.
// Remove that dependency, since a module cannot depend on itself.
$required = array_diff(drupal_required_modules(), [
$profile,
]);
$locale = !empty($langcode) && $langcode != 'en' ? [
'locale',
] : [];
// Merge dependencies, required modules and locale into install list and
// remove any duplicates.
$info['install'] = array_unique(array_merge($info['install'], $required, $info['dependencies'], $locale));
// If the profile has a config/sync directory use that to install drupal.
if (is_dir($profile_path . '/config/sync')) {
$info['config_install_path'] = $profile_path . '/config/sync';
}
$cache[$profile][$langcode] = $info;
}
return $cache[$profile][$langcode];
}