Toolkit

DrupalCommands extends AbstractCommands
in package

Drupal commands to setup and install a Drupal 8 site.

Table of Contents

Properties

$blockEnd  : string
Comment ending the Toolkit settings block.
$blockStart  : string
Comment starting the Toolkit settings block.

Methods

drupalCheckPermissions()  : int
Command to check the forbidden permissions.
drupalDisableCache()  : CollectionBuilder
Disable aggregation and clear cache.
drupalDrushSetup()  : CollectionBuilder
Write Drush configuration file at "${drupal.root}/drush/drush.yml".
drupalPermissionsSetup()  : CollectionBuilder
Setup Drupal permissions.
drupalSettingsSetup()  : CollectionBuilder
Setup Drupal settings.php file in compliance with Toolkit conventions.
drupalSiteInstall()  : CollectionBuilder
Install target site.
drupalSiteInstallValidate()  : void
Validate command drupal:site-install.
drupalSitePostInstall()  : CollectionBuilder
Run Drupal post-install commands.
drupalSitePreInstall()  : CollectionBuilder
Run Drupal pre-install commands.
drupalUpgradeStatus()  : int
Check project compatibility for Drupal 9/10/11 upgrade.
getConfigurationFile()  : string
Path to YAML configuration file containing command defaults.
getJson()  : array<string|int, mixed>
Returns the JSON parsed content.
getWorkingDir()  : string
Returns the current working directory.
isWebsiteInstalled()  : bool
Check if the website is installed.
getBin()  : string
Validate and return the path to given bin.
getBinPath()  : string
Return the path to given bin.
getConfigValue()  : mixed|null
Return the configuration value.
getNodeBin()  : string
Validate and return the path to given bin from node packages.
getNodeBinPath()  : string
Return the path to given bin from node packages.
getPnpmBin()  : string
Return the path to pnpm.
getSettingsBlockRegex()  : string
Remove settings block from given content.
getToolkitSettingsBlock()  : string
Helper function to update settings.php file.
isJunit()  : bool
Check whether Junit option is being used, or env var is set.
isSimulating()  : bool
Check if current command is being executed with option simulate.
processPrePostInstallCommands()  : void
Process pre and post install string-only commands by replacing given tokens.
taskExecute()  : CollectionBuilder
Execute a command.
taskProcess()  : ReplaceBlock|CollectionBuilder
Process the file.
taskReplaceBlock()  : ReplaceBlock|CollectionBuilder
Replace block in a file.

Properties

$blockEnd

Comment ending the Toolkit settings block.

protected string $blockEnd = '// End Toolkit settings block.'

$blockStart

Comment starting the Toolkit settings block.

protected string $blockStart = '// Start Toolkit settings block.'

Methods

drupalCheckPermissions()

Command to check the forbidden permissions.

public drupalCheckPermissions(ConsoleIO $io[, array<string|int, mixed> $options = ['endpoint' =>InputOption::VALUE_REQUIRED, 'blocker' =>InputOption::VALUE_NONE] ]) : int
Parameters
$io : ConsoleIO
$options : array<string|int, mixed> = ['endpoint' => InputOption::VALUE_REQUIRED, 'blocker' => InputOption::VALUE_NONE]

Command options.

Tags
command

drupal:check-permissions

option

endpoint The endpoint to use to connect to QA Website.

blocker If given and in case of error the command will fail.

SuppressWarnings

(PHPMD.CyclomaticComplexity)

(PHPMD.NPathComplexity)

Return values
int —

Command exit code.

drupalDisableCache()

Disable aggregation and clear cache.

public drupalDisableCache() : CollectionBuilder
Tags
command

drupal:disable-cache

Return values
CollectionBuilder —

Collection builder.

drupalDrushSetup()

Write Drush configuration file at "${drupal.root}/drush/drush.yml".

public drupalDrushSetup([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED, 'config-dir' =>InputOption::VALUE_REQUIRED] ]) : CollectionBuilder

Configuration file contents can be customized by editing "drupal.drush" values in your local runner.yml.dist/runner.yml, as shown below:

drupal: drush: options: ignored-directories: "${drupal.root}" uri: "${drupal.base_url}"

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED, 'config-dir' => InputOption::VALUE_REQUIRED]

Command options.

Tags
command

drupal:drush-setup

option

root Drupal root.

config-dir Directory where to store Drush 9 configuration file.

Return values
CollectionBuilder —

The drupal drush setup.

drupalPermissionsSetup()

Setup Drupal permissions.

public drupalPermissionsSetup([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED, 'sites-subdir' =>InputOption::VALUE_REQUIRED] ]) : CollectionBuilder

This command will set the necessary permissions on the default folder.

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED, 'sites-subdir' => InputOption::VALUE_REQUIRED]

Command options.

Tags
command

drupal:permissions-setup

option

root Drupal root.

sites-subdir Drupal site subdirectory.

Return values
CollectionBuilder —

The permissions set status task.

drupalSettingsSetup()

Setup Drupal settings.php file in compliance with Toolkit conventions.

public drupalSettingsSetup([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED, 'sites-subdir' =>InputOption::VALUE_REQUIRED, 'force' => false, 'skip-permissions-setup' => false] ]) : CollectionBuilder

This command will:

  • Copy "default.settings.php" to "settings.php", which will be overridden if existing
  • Add database and config directory settings using environment variables
  • Append to "settings.php" an include operation for a "settings.override.php" file

You can specify additional settings.php portions in your local runner.yml.dist/runner.yml as shown below:

drupal: additional_settings: | $config['cas.settings']['server']['hostname'] = getenv('CAS_HOSTNAME'), $config['cas.settings']['server']['port'] = getenv('CAS_PORT');

You can specify additional service parameters in your local runner.yml.dist/runner.yml as shown below:

drupal: service_parameters: session.storage.options: cookie_domain: '.europa.eu'

The settings override file name cannot be changed, changing the "drupal.site.settings_override_file" property will have no effect.

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED, 'sites-subdir' => InputOption::VALUE_REQUIRED, 'force' => false, 'skip-permissions-setup' => false]

Command options.

Tags
command

drupal:settings-setup

option

root Drupal root.

sites-subdir Drupal site subdirectory.

force Drupal force generation of a new settings.php.

skip-permissions-setup Drupal skip permissions setup.

Return values
CollectionBuilder —

Collection builder.

drupalSiteInstall()

Install target site.

public drupalSiteInstall([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED, 'base-url' =>InputOption::VALUE_REQUIRED, 'site-name' =>InputOption::VALUE_REQUIRED, 'site-mail' =>InputOption::VALUE_REQUIRED, 'site-profile' =>InputOption::VALUE_REQUIRED, 'site-locale' =>InputOption::VALUE_REQUIRED, 'account-name' =>InputOption::VALUE_REQUIRED, 'account-password' =>InputOption::VALUE_REQUIRED, 'account-mail' =>InputOption::VALUE_REQUIRED, 'database-type' =>InputOption::VALUE_REQUIRED, 'database-scheme' =>InputOption::VALUE_REQUIRED, 'database-user' =>InputOption::VALUE_REQUIRED, 'database-password' =>InputOption::VALUE_REQUIRED, 'database-host' =>InputOption::VALUE_REQUIRED, 'database-port' =>InputOption::VALUE_REQUIRED, 'database-name' =>InputOption::VALUE_REQUIRED, 'database-prefix' =>InputOption::VALUE_REQUIRED, 'sites-subdir' =>InputOption::VALUE_REQUIRED, 'config-dir' =>InputOption::VALUE_REQUIRED, 'site-update' =>InputOption::VALUE_NONE, 'existing-config' => false, 'skip-permissions-setup' => false] ]) : CollectionBuilder

This command will install a target Drupal site using configuration values provided in local runner.yml.dist/runner.yml files.

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED, 'base-url' => InputOption::VALUE_REQUIRED, 'site-name' => InputOption::VALUE_REQUIRED, 'site-mail' => InputOption::VALUE_REQUIRED, 'site-profile' => InputOption::VALUE_REQUIRED, 'site-locale' => InputOption::VALUE_REQUIRED, 'account-name' => InputOption::VALUE_REQUIRED, 'account-password' => InputOption::VALUE_REQUIRED, 'account-mail' => InputOption::VALUE_REQUIRED, 'database-type' => InputOption::VALUE_REQUIRED, 'database-scheme' => InputOption::VALUE_REQUIRED, 'database-user' => InputOption::VALUE_REQUIRED, 'database-password' => InputOption::VALUE_REQUIRED, 'database-host' => InputOption::VALUE_REQUIRED, 'database-port' => InputOption::VALUE_REQUIRED, 'database-name' => InputOption::VALUE_REQUIRED, 'database-prefix' => InputOption::VALUE_REQUIRED, 'sites-subdir' => InputOption::VALUE_REQUIRED, 'config-dir' => InputOption::VALUE_REQUIRED, 'site-update' => InputOption::VALUE_NONE, 'existing-config' => false, 'skip-permissions-setup' => false]

Command options.

Tags
command

drupal:site-install

option

root Drupal root.

site-name Site name.

site-mail Site mail.

site-profile Installation profile

site-locale Default site locale.

account-name Admin account name.

account-password Admin account password.

account-mail Admin email.

database-scheme Database scheme.

database-host Database host.

database-port Database port.

database-name Database name.

database-user Database username.

database-password Database password.

database-prefix Database prefix.

sites-subdir Sites subdirectory.

site-update Whether to enable the update module or not during installation.

existing-config Whether existing config should be imported during installation.

skip-permissions-setup Whether to skip making the settings file and folder writable during installation.

aliases

drupal:si,dsi

Return values
CollectionBuilder —

The collection builder.

drupalSiteInstallValidate()

Validate command drupal:site-install.

public drupalSiteInstallValidate(CommandData $commandData) : void
Parameters
$commandData : CommandData

The command data object.

Tags
hook

validate drupal:site-install

throws
Exception

Thrown when the settings file or its containing folder does not exist or is not writeable.

Return values
void —

Drupal site install validate status.

drupalSitePostInstall()

Run Drupal post-install commands.

public drupalSitePostInstall([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED] ]) : CollectionBuilder

Commands have to be listed under the "drupal.post_install" property in your local runner.yml.dist/runner.yml files, as shown below:

drupal: ... post_install: - "./vendor/bin/drush en views -y" - { task: "process", source: "behat.yml.dist", destination: "behat.yml" }

Post-install commands are automatically executed after installing the site when running "drupal:site-install".

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED]

Command options.

Tags
command

drupal:site-post-install

option

root The Drupal root. All occurrences of "!root" in the post-install string-only commands will be substituted with this value.

Return values
CollectionBuilder —

Collection builder.

drupalSitePreInstall()

Run Drupal pre-install commands.

public drupalSitePreInstall([array<string|int, mixed> $options = ['root' =>InputOption::VALUE_REQUIRED] ]) : CollectionBuilder

Commands have to be listed under the "drupal.pre_install" property in your local runner.yml.dist/runner.yml files, as shown below:

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED]

Command options.

drupal: ... pre_install: - { task: "symlink", from: "../libraries", to: "${drupal.root}/libraries" } - { task: "process", source: "behat.yml.dist", destination: "behat.yml" }

Pre-install commands are automatically executed before installing the site when running "drupal:site-install".

Tags
command

drupal:site-pre-install

option

root The Drupal root. All occurrences of "!root" in the pre-install string-only commands will be substituted with this value.

Return values
CollectionBuilder —

The drupal site tasks to be executed.

drupalUpgradeStatus()

Check project compatibility for Drupal 9/10/11 upgrade.

public drupalUpgradeStatus() : int
Tags
command

drupal:upgrade-status

aliases

tdus

SuppressWarnings

(PHPMD.CyclomaticComplexity)

(PHPMD.NPathComplexity)

Return values
int

getConfigurationFile()

Path to YAML configuration file containing command defaults.

public getConfigurationFile() : string
Return values
string —

Configuration file path.

getJson()

Returns the JSON parsed content.

public getJson(string $filename[, bool $throwException = true ]) : array<string|int, mixed>
Parameters
$filename : string
$throwException : bool = true

If the file is not found.

Return values
array<string|int, mixed> —

Json parsed content.

getWorkingDir()

Returns the current working directory.

public getWorkingDir() : string
Return values
string —

The current working directory.

isWebsiteInstalled()

Check if the website is installed.

public isWebsiteInstalled() : bool
Return values
bool

getBin()

Validate and return the path to given bin.

protected getBin(string $name) : string
Parameters
$name : string

The bin to look for.

Tags
throws
TaskException
Return values
string —

The bin path.

getBinPath()

Return the path to given bin.

protected getBinPath(string $name) : string
Parameters
$name : string
Return values
string —

The path to given binary.

getConfigValue()

Return the configuration value.

protected getConfigValue(string $key[, mixed|null $default = null ]) : mixed|null
Parameters
$key : string

The config item to look up.

$default : mixed|null = null

Default configuration value for the key item if neither has value nor exists.

Return values
mixed|null —

The configuration value.

getNodeBin()

Validate and return the path to given bin from node packages.

protected getNodeBin(string $name) : string
Parameters
$name : string

The bin to look for.

Tags
throws
TaskException
Return values
string —

The bin path.

getNodeBinPath()

Return the path to given bin from node packages.

protected getNodeBinPath(string $name) : string
Parameters
$name : string
Return values
string —

The path to given binary.

getPnpmBin()

Return the path to pnpm.

protected getPnpmBin() : string

The path is not part of the $PATH variable and cannot be used globally.

Return values
string —

The path to given pnpm.

getSettingsBlockRegex()

Remove settings block from given content.

protected getSettingsBlockRegex() : string
Return values
string —

Content without setting block.

getToolkitSettingsBlock()

Helper function to update settings.php file.

protected getToolkitSettingsBlock() : string
Return values
string —

Database configuration to be attached to Drupal settings.php.

isJunit()

Check whether Junit option is being used, or env var is set.

protected isJunit() : bool
Return values
bool

isSimulating()

Check if current command is being executed with option simulate.

protected isSimulating() : bool
Return values
bool —

True if using --simulate, false otherwise.

processPrePostInstallCommands()

Process pre and post install string-only commands by replacing given tokens.

protected processPrePostInstallCommands(array<string|int, string> &$commands, array<string|int, string> $tokens) : void
Parameters
$commands : array<string|int, string>

List of commands.

$tokens : array<string|int, string>

Replacement key-value tokens.

Return values
void —

The process pre and post install commands.

taskExecute()

Execute a command.

protected taskExecute(array<string|int, string> $tasks) : CollectionBuilder
Parameters
$tasks : array<string|int, string>

An array with tasks to execute.

Return values
CollectionBuilder —

The task executed.

taskProcess()

Process the file.

protected taskProcess(string $source[, string $destination = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
$source : string

The source file to process.

$destination : string = ''

The destination file.

Return values
ReplaceBlock|CollectionBuilder —

The file task processed.

taskReplaceBlock()

Replace block in a file.

protected taskReplaceBlock([string $filename = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
$filename : string = ''

The file to process.

Return values
ReplaceBlock|CollectionBuilder —

The file replaced.

On this page

Search results