This project is not covered by Drupal’s security advisory policy.
Tools utilities for modules. This module is useless, alone by itself.
Drupal 8/9 module with helpers, config form and controller to easily provide some module functionality.
It provides abstraction classes:
- AtoolsConfigForm which help with setting up the configuration of a module
- AtoolsBlockBase which help with setting up the form of a block
- AtoolsController with the possibility to set up a controller that only returns a stripped response.
It allows the management and generation of configuration form from YML files.
Form generation
The generation of the form is enabled by two files, which define the structure of the form and a list of fields in YML format.
These files must be placed in the `config/tools` folder of the module which uses the generation of settings.
An example of each of the files is provided in this module.
Fields file
The file %NAME%.fields.yml define a list of fields to be managed or saved by the form. It is a succession of field[: value] set in a YML way.
If you just need the fields list, because you override the getDefaultFieldValue() method in your form object with something more appropriate, you use the indexed array YAML format :
- debug
- cache
- cache_time
If you also want to specify the default values in the file, you have to use the associative array YAML format :
debug: false
cache: false
cache_time: 300
Structure file
The file %NAME%.form.yml define the structure to be used to generate the form.
It is more or less the structure you end up with when you declare your form array manually.
The only are that you do not use the '#' in front of keys, and you declare children of an element in a '_fields' element.
general:
type: fieldset
title: General settings
_fields:
debug:
type: checkbox
title: 'Debug mode'
description: 'Enable debug mode to show information'
cache:
type: checkbox
title: 'Activate cache'
description: 'Enable caching'
cache_time:
type: textfield
title: 'Cache expiration'
description: 'Cache expiration in second. 0 or empty is for none (do not use)'AtoolsConfigForm
This class is typically to use with module settings form. It extends `ConfigFormBase` and allow you to simply declare the form depending on YML files in the `config/tools` directory of the module.
The two files will have to be named 'MODULE_NAME.settings.fields.yml' and 'MODULE_NAME.settings.form.yml'.
Here is an exemple of module settings :
namespace Drupal\afreshdesk\Form;
use Drupal\atools\Form\AtoolsConfigForm;
/**
* Configure freshdesk settings.
*/
class FreshdeskSettingsForm extends AtoolsConfigForm {
/**
* Module machine name.
*
* @var string
*/
const MODULE_NAME = 'afreshdesk';
}
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.- Project categories: Developer tools
- Created by ccrosaz on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
