Appearance
Code generators are used to generate text codes, which are then sent to phone numbers for verification.
Custom code generator
A code generator implements CodeGeneratorInterface, containing only the generateCode method. The generateCode method must return an instance of \Drupal\sms\PhoneNumberVerification\CodeGenerator\VerificationCode.
The context of the code, including the entity/object it is for, and the phone number, is provided as $context.
php
namespace Drupal\my_module;
use Drupal\sms\PhoneNumberVerification\CodeGenerator\CodeGeneratorInterface;
final class MyCodeGenerator implements CodeGeneratorInterface {
public function generateCode(VerificationCodeContext $context): VerificationCodeInterface {
return new VerificationCode((string) \random_int(100000, 999999));
}
}