Open marcelovani opened 7 years ago
Another proof of concept: Use twig + a new command to override services.
File: chain-site-mode.yml
# How to use
# site:mode --mode="dev"
command:
name: site:mode
description: 'Changes the site mode'
vars:
mode:
- dev
- prod
commands:
# System Performance
{% set keys = ['cache.page.use_internal', 'css.preprocess', 'css.gzip', 'js.preprocess', 'js.gzip', 'response.gzip'] %}
{% for key in keys %}
- command: config:override
arguments:
name: system.performance
key: {{ key }}
value: {% if mode == "dev" %} false {% else %} true {% endif %}
{% endfor %}
# Views settings
{% set keys = ['ui.show.sql_query.enabled', 'ui.show.performance_statistics'] %}
{% for key in keys %}
- command: config:override
arguments:
name: views.settings
key: {{ key }}
value: {% if mode == "dev" %} false {% else %} true {% endif %}
{% endfor %}
# System Logging
- command: config:override
arguments:
name: system.logging
key: error_level
value: {% if mode == "dev" %} all {% else %} none {% endif %}
# Services http.response.debug_cacheability_headers
- command: service:override
arguments:
name: http.response.debug_cacheability_headers
key: error_level
value: {% if mode == "dev" %} true {% else %} false {% endif %}
# Services Twig config
{% set keys = ['debug', 'auto_reload', 'cache'] %}
{% for key in keys %}
- command: service:override
arguments:
name: twig.config
key: {{ key }}
value: {% if mode == "dev" %} true {% else %} false {% endif %}
{% endfor %}
The if/else is not working, I think I am using an invalid syntax
@marcelovani could you try using as :
{{ mode === 'dev' }}
or
{{ mode === 'dev' ?? false }}
Ok, try this https://github.com/hechoendrupal/drupal-console-core/pull/306/files with https://github.com/hechoendrupal/drupal-console/pull/3771/files
It works fine but the chain looks cluttered with all the twig stuff, I think its neater if we do the chain as per #3540
Testing:
Install a drupal site and run
drupal site:mode --mode="dev"
drupal site:mode --mode="prod"
Todo:
Issue title
[site:mode] Use chains to replace site:mode command
Problem/Motivation
Since chains are getting more powerful, I figured we could replace the code found in https://github.com/hechoendrupal/drupal-console/blob/master/src/Command/Site/ModeCommand.php with a chain
Details to include: We can simply have less code to maintain and add more flexibility to users
Solution
This is how the site:mode:dev chain would look
The prod chain would be the inverse of the chain above
This chain should appear only when there is a site installed, that would automatically happen when we implement https://github.com/hechoendrupal/drupal-console-core/issues/240