niji-digital / drupal-settings
Composer Plugin for generate the Drupal settings file.
Installs: 18 023
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 8
Forks: 4
Open Issues: 1
Type:composer-plugin
Requires
- php: >=5.4.5
- composer-plugin-api: ^1.0.0
- drupal/core: ~8.4
- twig/twig: ^1.23.1
Requires (Dev)
- composer/composer: dev-master
- phpunit/phpunit: ^4.4.0
This package is not auto-updated.
Last update: 2025-02-02 21:27:37 UTC
README
Composer plugin for generate the Drupal settings.local.php
(or other) file from a yaml parameter file.
Usage
- Run
composer require niji-digital/drupal-settings
- Add new script to the scripts section of your composer.json:
{ "scripts": { "prepare-settings": "NijiDigital\\Settings\\Plugin::generate" } }
-
Create the YAML parameters file (by default in
COMPOSER_ROOT/drupal-settings
directory, see Parameters section) -
Optional: Create the settings file template (see Template section)
-
Optional: Change the settings file destination (see Destination section)
-
Run
composer prepare-settings
From "Template" using "Parameters" to "Destination"
All path parameters must be relative to the composer root directory
Template
By default the settings.local.php.twig
template file present in this repository is used.
{% autoescape false %} <?php //$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'; //$settings['cache']['default'] = 'cache.backend.null'; $settings['extension_discovery_scan_tests'] = TRUE; $settings['file_chmod_directory'] = 0775; $settings['file_chmod_file'] = 0664; $settings['hash_salt'] = '{{ hash_salt }}'; $databases['default']['default'] = array( 'driver' => 'mysql', 'database' => '{{ db_name }}', 'username' => '{{ db_user }}', 'password' => '{{ db_pass }}', 'host' => '{{ db_host }}', 'port' => 3306, 'prefix' => '', 'collation' => 'utf8mb4_general_ci', 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', ); $config['system.logging']['error_level'] = '{{ error_level }}'; $config['system.performance']['css']['preprocess'] = {{ css_preprocess }}; $config['system.performance']['js']['preprocess'] = {{ js_preprocess }}; $config['system.performance']['cache.page.max_age'] = {{ cache_maxage }}; $settings['trusted_host_patterns'] = {{ trusted_host_patterns }}; $config_directories = array( CONFIG_SYNC_DIRECTORY => getcwd() . '/../config/' ); {% endautoescape %}
You can make your own template and add his definition in the composer extra data definition:
{ "extra": { "drupal-settings": { "template-directory": "path/to/templates", "template-file": "settings.local.php.twig" } } }
Parameters
Example:
cache_maxage: '300' css_preprocess: 'TRUE' db_host: 'mariadb' db_name: 'drupal' db_pass: 'drupal' db_user: 'drupal' error_level: 'verbose' js_preprocess: 'TRUE' trusted_host_patterns: - '^drupal\.localhost$'
This plugin tried to load parameter file (in order):
- The file defined in composer extra data definitions:
{ "extra": { "drupal-settings": { "parameters-file": "../path/to/parameters.yml" } } }
settings/parameters.yml
settings/parameters.dist.yml
Destination
By default the settings.local.php
file is created in the web/sites/default
directory.
The destination can be overwritten in composer extra data definition.
{ "extra": { "drupal-settings": { "destination-directory": "web/sites/default", "destination-file": "settings.local.php" } } }