Skip to content
Snippets Groups Projects
Unverified Commit d9ccf86f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3005689 by foxtrotcharlie, joachim, alexpott: improve docs for _install_select_profile()

parent 7151900f
No related branches found
No related tags found
No related merge requests found
...@@ -1270,12 +1270,19 @@ function install_select_profile(&$install_state) { ...@@ -1270,12 +1270,19 @@ function install_select_profile(&$install_state) {
/** /**
* Determines the installation profile to use in the installer. * Determines the installation profile to use in the installer.
* *
* A profile will be selected in the following order of conditions: * Depending on the context from which it's being called, this method
* may be used to:
* - Automatically select a profile under certain conditions.
* - Indicate which profile has already been selected.
* - Indicate that a profile still needs to be selected.
*
* A profile will be selected automatically if one of the following conditions
* is met. They are checked in the given order:
* - Only one profile is available. * - Only one profile is available.
* - A specific profile name is requested in installation parameters: * - A specific profile name is requested in installation parameters:
* - For interactive installations via request query parameters. * - For interactive installations via request query parameters.
* - For non-interactive installations via install_drupal() settings. * - For non-interactive installations via install_drupal() settings.
* - A discovered profile that is a distribution. If multiple profiles are * - One of the available profiles is a distribution. If multiple profiles are
* distributions, then the first discovered profile will be selected. * distributions, then the first discovered profile will be selected.
* - Only one visible profile is available. * - Only one visible profile is available.
* *
...@@ -1283,35 +1290,37 @@ function install_select_profile(&$install_state) { ...@@ -1283,35 +1290,37 @@ function install_select_profile(&$install_state) {
* The current installer state, containing a 'profiles' key, which is an * The current installer state, containing a 'profiles' key, which is an
* associative array of profiles with the machine-readable names as keys. * associative array of profiles with the machine-readable names as keys.
* *
* @return * @return string|null
* The machine-readable name of the selected profile or NULL if no profile was * The machine-readable name of the selected profile or NULL if no profile was
* selected. * selected.
*
* @see install_select_profile()
*/ */
function _install_select_profile(&$install_state) { function _install_select_profile(&$install_state) {
// Don't need to choose profile if only one available. // If there is only one profile available it will always be the one selected.
if (count($install_state['profiles']) == 1) { if (count($install_state['profiles']) == 1) {
return key($install_state['profiles']); return key($install_state['profiles']);
} }
// If a valid profile has already been selected, return the selection.
if (!empty($install_state['parameters']['profile'])) { if (!empty($install_state['parameters']['profile'])) {
$profile = $install_state['parameters']['profile']; $profile = $install_state['parameters']['profile'];
if (isset($install_state['profiles'][$profile])) { if (isset($install_state['profiles'][$profile])) {
return $profile; return $profile;
} }
} }
// Check for a distribution profile. // If any of the profiles are distribution profiles, return the first one.
foreach ($install_state['profiles'] as $profile) { foreach ($install_state['profiles'] as $profile) {
$profile_info = install_profile_info($profile->getName()); $profile_info = install_profile_info($profile->getName());
if (!empty($profile_info['distribution'])) { if (!empty($profile_info['distribution'])) {
return $profile->getName(); return $profile->getName();
} }
} }
// Get all visible (not hidden) profiles. // Get all visible (not hidden) profiles.
$visible_profiles = array_filter($install_state['profiles'], function ($profile) { $visible_profiles = array_filter($install_state['profiles'], function ($profile) {
$profile_info = install_profile_info($profile->getName()); $profile_info = install_profile_info($profile->getName());
return !isset($profile_info['hidden']) || !$profile_info['hidden']; return !isset($profile_info['hidden']) || !$profile_info['hidden'];
}); });
// If there is only one visible profile, return it.
if (count($visible_profiles) == 1) { if (count($visible_profiles) == 1) {
return (key($visible_profiles)); return (key($visible_profiles));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment