InstallProfile
Helpers related to working with install profiles.
- Full name:
\Drupal\helper\InstallProfile
Properties
schemaKeyValue
The module schema key/value store.
protected \Drupal\Core\KeyValueStore\KeyValueStoreInterface $schemaKeyValue
profileList
protected \Drupal\Core\Extension\ProfileExtensionList $profileList
configFactory
protected \Drupal\Core\Config\ConfigFactoryInterface $configFactory
moduleHandler
protected \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
updateHookRegistry
protected \Drupal\Core\Update\UpdateHookRegistry $updateHookRegistry
Methods
__construct
InstallProfileSwitcher constructor.
public __construct(\Drupal\Core\Extension\ProfileExtensionList $profileList, \Drupal\Core\Config\ConfigFactoryInterface $configFactory, \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler, \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $keyValueFactory, \Drupal\Core\Update\UpdateHookRegistry $updateHookRegistry): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$profileList |
\Drupal\Core\Extension\ProfileExtensionList | |
| The profile extension list service. | ||
$configFactory |
\Drupal\Core\Config\ConfigFactoryInterface | |
| The config factory. | ||
$moduleHandler |
\Drupal\Core\Extension\ModuleHandlerInterface | |
| The module handler. | ||
$keyValueFactory |
\Drupal\Core\KeyValueStore\KeyValueFactoryInterface | |
| The key/value storage factory. | ||
$updateHookRegistry |
\Drupal\Core\Update\UpdateHookRegistry | |
| The update hook registry. |
switch
Switches the site's install profile.
public switch(string $profile, int $schema_version = null): mixed
Note the following: - This does not run the new profile's install hooks. - Does not enable any of the profile's dependencies. - This does not check that currently enabled modules are located in the current profile's code and will no longer be available once switching to the new profile. - Does not run any uninstallation of the current profile, like removing any tables defined in hook_schema().
Parameters:
| Parameter | Type | Description |
|---|---|---|
$profile |
string | |
| The machine name of the profile to switch to. | ||
$schema_version |
int | |
| The schema version to set for the install profile. |
validateProfile
Validates a profile and checks its various requirements.
public validateProfile(string $profile): mixed
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:
| Parameter | Type | Description |
|---|---|---|
$profile |
string | |
| The profile name. |
Throws:
If the profile does not exist.
- InvalidArgumentException
If the profile failed any validations.
- InstallerException
getLatestSchemaVersion
Gets the latest schema version for an install profile.
protected getLatestSchemaVersion(string $profile): int
Parameters:
| Parameter | Type | Description |
|---|---|---|
$profile |
string | |
| The install profile name. |
Return Value:
The schema version.
formatRequirementsReasons
Convert an array of requirements into a simpler list of reasons.
protected formatRequirementsReasons(array $requirements): string[]
Parameters:
| Parameter | Type | Description |
|---|---|---|
$requirements |
array | |
| An array of requirements from hook_requirements(). |
Return Value:
An array of requirement reasons as strings.
checkEnabledProfileExtensions
Check for any enabled extensions that reside inside the current profile.
protected checkEnabledProfileExtensions(string $profile, string $type): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$profile |
string | |
| The new desired profile. | ||
$type |
string | |
| The extension type. Possible values are module or theme. |
Throws:
If there are extensions that enabled in the current profile that do not
also reside in the new profile.
- InstallerException