This issue comes partially from discussions with nyariv re #2791905: Consolidate features with SMS Framework.
We should make our entity phone number number system as flexible as possible, that is, compatible with external verification systems like Mobile Number.
New service
Create a new service and move PhoneNumberProvider::getPhoneNumbers and PhoneNumberProvider::sendMessage into it. This will make the service easy to override without having to override SMSFwk verification systems.
The existing service/methods can be marked as deprecated.
Add an event
Create an event (aka hook) within PhoneNumberProvider::getPhoneNumbers allowing Drupal modules to hook into getting phone numbers for an entity. The SMS Framework specific logic within the current getPhoneNumbers can be moved to a subscriber of this new event.
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | entity-phone-number-event-2797121-43.patch | 13.56 KB | dpi |
| #41 | entity-phone-number-event-2797121-41.patch | 13.56 KB | dpi |
| #37 | entity-phone-number-event-2797121.patch | 13.65 KB | dpi |
| #27 | sms-verification-new-service-2797121-27-ba284e4.patch | 67.18 KB | dpi |
| #22 | sms-verification-new-service-2797121-22-32ac2fc.patch | 57.69 KB | dpi |
Comments
Comment #2
dpiComment #3
nyariv commentedGreat idea!
Mobile number however does not assume a single phone number field for an entity, so a field parameter would be needed. This is solved by SmsF with the phone number config entities that wrap around entities which identifies a single field per entity. Mobile number could work with that if SmsF allowed selection of Mobile Number fields when selecting the field for the entity in the phone number ui. Mobile Number has the 'value' property in common with telephone fields, so it should be simple integration, but there are a couple issues with that:
Of course this is a one option, another is for Mobile Number to implement a similar single field per entity configuration, but that would create more duplication and confusion between the two modules.
I noticed that the for verification the SmsF widget is needed, perhaps the verification settings and functionality can be offloaded to the widget. This is what I did for Mobile Number in the 7.x branch, although verification is not really enabled for telephone fields.
Comment #4
dpiWe do not assume a phone number per entity. Hence the plural naming and return signature of
PhoneNumberProvider::getPhoneNumbers. I believe the auto-field creation uses single phone number. Theoretically the events proposed by OP will allow both verification systems to co-exist.I am not proposing that you have integration with our verification systems, auto field creation, administrative UI controls. Pretty much anything in
PhoneNumberProviderother thangetPhoneNumbers()andsendMessage()is ours and is customized to our usage.You can keep your own verification system, including its own field type, verification messages etc. And optionally you could disable ours UI's via route access control, so it does not confuse admins.
Comment #5
nyariv commentedI didn't mean a single phone number, I meant a single field is assumed, because the config entity allows only one field to be set per bundle.
Yes, I'm talking about
getPhoneNumbers(), it either needs a field name parameter, or I would have to duplicate the single field per bundle config that you implemented. Or you could allow your config entity to support one more field type, which is what I proposed, perhaps through a hook/event.I think the config setup in SmsF is properly implemented, I wouldn't want to override its routing, especially if it can work for other things, such that other modules may use PhoneNumberProvider.
Comment #6
dpiRighto. I dont think this is going to change anytime soon. Its quite nontrivial/would require update path.
Our system is based on telephone field. If we allowed other fields, then we may have to write code specifically on how to get/set field values (especially multi value/column fields). We cannot always expect to get/set a phone number with
$entity->yourphonefield.Even if our system allowed multiple fields, why would it need a field name param? Why couldnt it just get all of them? I feel callers to
getPhoneNumbers()shouldn't have to care about what field its getting data from.Comment #7
dpiIm not sure how you are going to handle setting phone numbers with multiple verification providers or multiple fields. sms_user already sets phone numbers in its account registration service, but assumes our verification system.
Comment #8
nyariv commentedIndeed, that's why I think a hook / event is needed, one for allowed field types, and one for pulling number from the field. In the case of mobile number the latter won't be needed because it uses 'value' property similarly to telephone, while the other properties can be ignored.
In the case of 'Telephone', one field may be for a mobile number while another for a landline, ie 'work number', etc. For Mobile Number it may be a backup phone number or something similar. In both cases the order of field appearance in the entity (alphabetical?) may not correspond with main number being first, and you wouldn't want to send the sms to the other numbers. Or at least the return value for getPhoneNumbers() should specify the field name + delta for each number
Yeah, you can't have both verification systems applied to the same field, which is why it should be separated from the more generic phone number config. It would seem the ideal place to put the verification settings is in the widget, this way the user has to choose either or. Although as it stands right now, my verification system can't work with telephone, and yours cant with Mobile Number although it's possible but the field settings would confuse the user because that is where the verification settings are. In the case of sms_user, again a hook/event would be useful here but not needed for Mobile Number because of the value property.
Phone number config doesn't have to support multiple fields per bundle, I think it actually simplifies things for the admin, but support for additional field types should be allowable with hooks.
Comment #9
dpiAs far as broadening our verification system, I'd be looking at 6-18 months for that. Its not exactly a high priority, we have plenty of unimplemented things in the issue queue to address first. I see verifications as solved — for now.
Though, the service and event defined in the OP is near term. Hopefully before 1.0, maybe 1.1.
Plan your module accordingly.
Comment #10
dpiAdding 'beta target' since its a nice to have.
Comment #11
nyariv commentedIndeed, and thanks for taking my humble module into consideration. I will see how it can be integrated with the changes.
Comment #12
dpiWe'll do the event later.
This patch just splits the service up. There is no new functionality.
Review at: https://github.com/dpi/smsframework/pull/58
Comment #17
dpiComment #22
dpiMore old references.
Comment #27
dpiFixed bad @covers
Comment #28
nyariv commentedTested patch on simplytest.me. No errors, but sms's do not seem to be sent.
Steps:
1) Install smsframework 8.x-1.x with patch, and telephone. Standard drupal profile.
2) Add telephone field to user
3) Create phone number config, only selecting bundle and field, no other changes, and save.
4) Go to admin user edit page, insert a phone number in telephone field (smsf's widget already applied).
5) Save user
6) Verification sms log does not appear in watchdog. Although it shows there are unverified numbers on admin/config/smsframework/phone_number
Comment #29
dpiThe patch doesn't do anything other than move functions around. There is no behavior change between the patch and whatever you have on your local dev machine.
Are you sure you are not getting the SMS because it is queued? Or you have not configured the gateway as fallback?
I cannot repro this on my machine, and I know we have decent coverage of the verification systems.
Comment #30
dpiThe reason why the patch is still in limbo is:
sms.phone_number.verification.Comment #31
nyariv commentedI tested with simpletest.me which creates a clean install Drupal environment in the cloud with a module of choice for testing. It uses only publicly available code, including the above patch.
Does the queue get cleared on cron? I tried running cron manually but that didn't help. I will try it on my dev as well. It could mean the module does not work with default config.
Comment #32
almaudoh commentedI'd done a quick review on the PR but forgot to submit it. Looks good.
Comment #33
dpiFantastic.
Remaining task in this issue is implementation of the event.
Comment #35
almaudoh commentedThis should not block the release of a beta then. I will go ahead and tag a beta by the end of tomorrow if nothing else comes up before then and if you don't beat me to it.
Comment #36
dpiIt shouldn't. Event target is 1.0, or 1.1.
Comment #37
dpiReady for review, PR: https://github.com/dpi/smsframework/pull/61
There are no functionality changes, or API removals. These were already done in the service separation in the previous patch. This patch is primarily moving internal functionality around, and adds a entity phone number event.
Travis is green, patch should pass here.
@nyariv, there is a code sample in sms.api.php, for your module to hook into. Please review the changes, let me know if there is anything you require.
Commit log
Comment #38
dpiadded release-8.x-1.0-beta2 tag.
Comment #39
dpiPatch isn't high priority, can wait til beta 3.
@nyariv, Would be great to get some attention on this, when you have some time through Jan.
Comment #40
almaudoh commentedStill doing this in beta3? Also, phone number verification as a whole needs better documentation.
Comment #41
dpiStraight reroll
Comment #42
nyariv commentedSorry, I had been preoccupied with other matters and hadn't noticed you needed my input. The api looks good.
Comment #43
dpiReroll
Comment #44
dpi@ #40
@almaudoh
Which aspect needs docs?
Comment #47
dpiRerolled, but there were no differences.
45 failed because head is failing in D8.
Committed!