public function InstallProfile::validateProfile in Helper 8
Validates a profile and checks its various requirements.
This method performs the following validations:
- Does the profile exist?
- Does the profile have all of its module dependencies currently enabled?
- Does the profile or any of its dependencies fail any hook_requirements() checks with errors?
- Does the current profile have any enabled modules or themes inside of it that will go "missing" when switching to the new profile?
Parameters
string $profile: The profile name.
Throws
\InvalidArgumentException If the profile does not exist.
\Drupal\Core\Installer\Exception\InstallerException If the profile failed any validations.
File
- src/
InstallProfile.php, line 153
Class
- InstallProfile
- Helpers related to working with install profiles.
Namespace
Drupal\helperCode
public function validateProfile($profile) {
// Ensure the profile exists.
if (!$this->profileList
->exists($profile)) {
throw new \InvalidArgumentException("The {$profile} profile does not exist.");
}
// Ensure that the desired profile is different from the current profile.
if ($profile === \Drupal::installProfile()) {
throw new \InvalidArgumentException("The current install profile is already set to {$profile}.");
}
// Make sure the installation API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Check that the profile's dependencies are already enabled.
$info = install_profile_info($profile);
if (!empty($info['dependencies']) && ($missing_dependencies = array_diff($info['dependencies'], array_keys($this->moduleHandler
->getModuleList())))) {
sort($missing_dependencies);
throw new InstallerException("The following module dependencies are not enabled or are missing for the {$profile} profile: " . implode(', ', $missing_dependencies) . '.');
}
// Ensure that the profile's .install file and classes are available, since
// drupal_check_profile only does this for the install profile's
// dependencies, but not the install profile itself.
$profile_path = drupal_get_path('profile', $profile);
$profile_install_file = DRUPAL_ROOT . '/' . $profile_path . "/{$profile}.install";
\Drupal::service('class_loader')
->addPsr4('Drupal\\' . $profile_path . '\\', \Drupal::root() . "/{$profile_path}/src");
if (is_file($profile_install_file)) {
require_once $profile_install_file;
}
// Ensure that requirements are checked for the new profile.
$requirements = drupal_check_profile($profile);
if (is_array($requirements) && drupal_requirements_severity($requirements) === REQUIREMENT_ERROR) {
$reasons = $this
->formatRequirementsReasons($requirements);
throw new InstallerException("Failed requirements check for the {$profile} profile:\n" . implode("\n", $reasons));
}
// Check for any modules or themes inside the profile that are enabled and
// may not be available in the new profile.
$this
->checkEnabledProfileExtensions($profile, 'module');
$this
->checkEnabledProfileExtensions($profile, 'theme');
}