Appearance
Installation
SMS Framework can be installed by:
sh
composer require drupal/sms
drush module:enable sms
Configuration
SMS Framework is configured with service parameters. This is a different process to Drupal configuration. Service parameters and configuration have commonality in that they can be found on-disk as YAML.
The current list of service parameters can be found in sms.services.yml
, along with extra documentation. By defining a parameter, the associated value in sms.services.yml
is fully overridden.
The sms.transports
parameter is the only parameter expected to be overridden. The sms.verification
parameter can be left as-is if the defaults are good.
WARNING
If sms.verification
is overridden, the full list of values must be redefined.
Defaults
yaml
parameters:
sms.transports:
mytransport: 'my-transport://default'
sms.verification:
enabled: true
route:
path: '/verify'
success: '/user'
unique: true
unverified:
lifetime: 900
purge_fields: true
message: |-
Your verification code is '[sms-message:verification-code]'.
Go to [sms:verification-url] to verify your phone number.
- [site:name]
Overriding service parameters
In the site directory, usually sites/default/
, create a services.yml
file.
Add to settings.php
:
php
$settings['container_yamls'][] = __DIR__ . '/services.yml';
Add to services.yml
:
yaml
parameters:
sms.transports:
# ...
sms.verification:
# ...
Environment specific configuration
Configuration may need to be different depending on environment, for example by using the Fake or custom transport on non-production environments, and the real SMS transport only on production.
For regular Drupal configuration Config Splits or Config overrides may be utilised to have differing configuration per environment. For service files though, this behavior can be replicated by conditionally including YAML files with container_yamls
:
php
if ($environmentIsLocal) {
$settings['container_yamls'][] = __DIR__ . '/sms.local.services.yml';
}
if ($environmentIsProduction) {
$settings['container_yamls'][] = __DIR__ . '/sms.production.services.yml';
}
Notifier
Phone number configuration can be found in Notifier, which produces SMS recipients from a field mapping between entities and fields:
yaml
notifier.field_mapping.sms:
- entity_type: user
bundle: user
field_name: phone_number
An additional key in this mapping determines whether verification is enabled:
yaml
notifier.field_mapping.sms:
- entity_type: user
bundle: user
field_name: phone_number
verification: true
Default behavior
verification: true
is the default for when the verification
key is omitted from notifier.field_mapping.sms
.