Custom Modules
CoB custom modules - usually taxonomy, nodes and paragraphs.
Boston.gov Conventions
The following development conventions are being followed in developing boston.gov modules.
Module naming and location
City of Boston have the following naming and grouping conventions for custom modules:
Twig Templates
Templates for the component should be saved in:
To add a customized template, select a suggestion for the base (node, field, region etc), then
Save the template in the folder above
In the
module_name_theme()
hook inmodule_name.module
add the following:If a new suggestion is needed, then add the following:
Where XXX is the appropriate entity type (node, field, region, etc etc) to add a suggestion to.
Theme overriding
Wherever possible, the style provided from the patterns library should be used. In practice this means that boston.gov can be styled by a Drupal developer ensuring that the twig template files provide HTML structured and given classes that the patterns library expects.
Should the need arise, then the patterns library style sheets can be overridden. Typically this is done at the module level, although if multiple modules will use the override, consider placing it in the bos_theme
theme.
To add overrides,
Create the style sheet
module_name.css
and appropriate markup in the relevant template (see above section),Save the stylesheet in:
Update (or create) the
module_name.libraries.yml
file with the following:Using a
module_name_preprocess_HOOK()
hook inmodule_name.module
attach the css where and only when it is required. For example:
Using JavaScript
Wherever possible, JavaScript should not be used on boston.gov. This is to maintain compatibility with as many browsers as possible, and to maximize accessibility for screen readers etc.
Should the need arise, then a JavaScript library can be created and deployed. Typically this is done at the module level, although if multiple modules will use the override, consider placing it in the bos_theme
theme.
To add overrides,
Create the JavaScript library
module_name.js
,Save the library in:
Update (or create) the
bos_modulename.libraries.yml
with the JavaScript directive - for example you could add the following:Using a
bos_modulename_preprocess_HOOK()
hook inbos_modulename.module
attach the JavaScript library where and only when it is required. For example:
Site and Module Configuration
Drupal 8 defines settings and configurations in YML files with the actual "current" settings and configurations being stored in the Drupal (MySQL) database.
When the website is deployed or the web-server is restarted, configurations are re-read from the database. To reload the configuration and settings from yml files requires a manual (usually drush
) process to be run by a developer.
Clearing the sites caches causes cached configurations and settings to be replaced with values from the database. Clearing caches does not reload yml files.
Importing YML configuration into the database.
YML files in a modulesdocroot/modules/custom/ ... /module_name/config/install
folder will be imported into the database when a module is first installed.
YML files in the docroot/../config/default/
folder will be imported into the database when the configuration is imported via the Drupal UI, or the drush
command.
Exporting all database settings to YML files.
Current (run-time) settings and configurations in the database can be exported to the docroot/../config/default/
folder via the Drupal UI, or the drush
command.
Defining module-specific configurations using config_devel.
If the config_devel
module is enabled then a modules configuration can be exported to the modules config/install
folder.
The dependent configurations are defined in the module_name.info.yml
file as follows:
To export these configurations to the config/install
folder use the following drush command:
Configuration considerations
Modules should try to reuse
field.storage.entity-type.field_name
configurations wherever possible.field.storage.entity-type.field_name
configurations should be: 1. saved in the modules parent module (e.g.bos_components
orbos_content
)to enable sharing, and 2. added to the parentsconfig_devel
section of the.info.yml
file.
Last updated