Toolkit

DrupalCommands extends AbstractCommands
in package

Drupal commands to setup and install a Drupal 8 site.

Table of Contents

$blockEnd  : string
Comment ending the Toolkit settings block.
$blockStart  : string
Comment starting the Toolkit settings block.
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()  : mixed
Validate command drupal:site-install.
drupalSitePostInstall()  : TaskInterface
Run Drupal post-install commands.
drupalSitePreInstall()  : TaskInterface
Run Drupal pre-install commands.
drupalUpgradeStatus()  : int
Check project compatibility for Drupal 9/10 upgrade.
getConfigurationFile()  : string
Path to YAML configuration file containing command defaults.
getWorkingDir()  : string
Returns the current working directory.
initializeRuntimeConfiguration()  : mixed
Command initialization.
getBin()  : string
Validate and return the path to given bin.
getBinPath()  : string
Return the path to given bin.
getConfigValue()  : mixed
{@inheritdoc}
getNodeBin()  : string
Validate and return the path to given bin from node packages.
getNodeBinPath()  : string
Return the path to given bin from node packages.
getSettingsBlockRegex()  : string
Remove settings block from given content.
getToolkitSettingsBlock()  : string
Helper function to update settings.php file.
isSimulating()  : bool
Check if current command is being executed with option simulate.
processPrePostInstallCommands()  : mixed
Process pre and post install string-only commands by replacing given tokens.
taskExecute()  : mixed
Execute a command.
taskProcess()  : Process|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

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]
Tags
command

drupal:drush-setup

option

root Drupal root.

option

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

Return values
CollectionBuilder

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]
Tags
command

drupal:permissions-setup

option

root Drupal root.

option

sites-subdir Drupal site subdirectory.

Return values
CollectionBuilder

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.

option

sites-subdir Drupal site subdirectory.

option

force Drupal force generation of a new settings.php.

option

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-update' => 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, 'sites-subdir' => InputOption::VALUE_REQUIRED, 'config-dir' => InputOption::VALUE_REQUIRED, '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-update' => 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, 'sites-subdir' => InputOption::VALUE_REQUIRED, 'config-dir' => InputOption::VALUE_REQUIRED, 'existing-config' => false, 'skip-permissions-setup' => false]
Tags
command

drupal:site-install

option

root Drupal root.

option

site-name Site name.

option

site-mail Site mail.

option

site-profile Installation profile

option

site-update Whereas to enable the update module or not.

option

site-locale Default site locale.

option

account-name Admin account name.

option

account-password Admin account password.

option

account-mail Admin email.

option

database-scheme Database scheme.

option

database-host Database host.

option

database-port Database port.

option

database-name Database name.

option

database-user Database username.

option

database-password Database password.

option

sites-subdir Sites subdirectory.

option

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

option

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

aliases

drupal:si,dsi

Return values
CollectionBuilder

drupalSiteInstallValidate()

Validate command drupal:site-install.

public drupalSiteInstallValidate(CommandData $commandData) : mixed
Parameters
$commandData : CommandData
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
mixed

drupalSitePostInstall()

Run Drupal post-install commands.

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

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]
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
TaskInterface

drupalSitePreInstall()

Run Drupal pre-install commands.

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

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

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".

Parameters
$options : array<string|int, mixed> = ['root' => InputOption::VALUE_REQUIRED]
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
TaskInterface

drupalUpgradeStatus()

Check project compatibility for Drupal 9/10 upgrade.

public drupalUpgradeStatus() : int
Tags
SuppressWarnings

(PHPMD.CyclomaticComplexity)

SuppressWarnings

(PHPMD.NPathComplexity)

command

drupal:upgrade-status

aliases

tdus

Return values
int

getConfigurationFile()

Path to YAML configuration file containing command defaults.

public getConfigurationFile() : string
Return values
string

getWorkingDir()

Returns the current working directory.

public getWorkingDir() : string
Return values
string

The current working directory.

initializeRuntimeConfiguration()

Command initialization.

public initializeRuntimeConfiguration() : mixed
Tags
hook

pre-command-event *

Return values
mixed

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()

{@inheritdoc}

protected getConfigValue(mixed $key[, mixed $default = null ]) : mixed
Parameters
$key : mixed
$default : mixed = null
Return values
mixed

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.

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.

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, mixed> &$commands, array<string|int, mixed> $tokens) : mixed
Parameters
$commands : array<string|int, mixed>

List of commands.

$tokens : array<string|int, mixed>

Replacement key-value tokens.

Return values
mixed

taskExecute()

Execute a command.

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

An array with tasks to execute.

Return values
mixed

taskProcess()

Process the file.

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

The source file to process.

$destination : string = ''

The destination file.

Return values
Process|CollectionBuilder

taskReplaceBlock()

Replace block in a file.

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

The file to process.

Return values
ReplaceBlock|CollectionBuilder

Search results