As the functionality of the Salesforce Web-to-Lead Webform Data Integration module has been moved into a webform handler, there now exists the possibility for the data to be passed to multiple salesforce accounts/data stores.

The existing hook, hook_sfweb2lead_webform_posted_data_alter(), works well for only one instance of the handler but control over per handler data changes is not possible.

To increase the flexibility of the module, another hook could be added that has the handler passed in.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Cook created an issue. See original summary.

John Cook’s picture

Status: Active » Needs review
FileSize
1.88 KB

I've created a new alter hook – hook_sfweb2lead_webform_handler_data_alter().

This hook has the data array, current handler, and the webform submission passed in.

This allows for the handler's configuration to be accessed and decisions to how the data is to be altered can be made from this information.

It may also be possible to deprecate the hook_sfweb2lead_webform_posted_data_alter() hook as the webform object can be obtained from the handler.

AaronBauman’s picture

Status: Needs review » Needs work

This is a good idea.
Some feedback:

1) seems a bit silly to have both those in succession, though i understand the instinct to preserve existing functionality. Let's mark the existing hook deprecated, and to be removed in 5.0 stable release. And let's fire a watchdog error for anyone still using it, so they know to replace their impelmentations.

2) let's replace it with an event dispatcher, instead of a hook. Let me know if you want help on figuring what that event should look like.

John Cook’s picture

Issue tags: +Novice
FileSize
5.22 KB

I've made a start at re-implementing this functionality as an event.

There's a new event, Sfweb2leadWebformEvent, that a subscriber can listen for. The existing hook functionality has also been wrapped in a subscriber for consistency.

There's a bit of type wrangling to try and make it easier with passing the submission data around.

There's no interdiff because this is essentially a new patch from master.

There's a bit of tidying up that needs to be done – mainly comments – so it's not ready for a proper review yet.

I'm adding the 'novice' tag for creating/updating the comments.

AaronBauman’s picture

Looks good so far.

A couple minor points real quick:

+    $salesforce_data_object = (object) $salesforce_data;
+    /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
+    $dispatcher = \Drupal::service('event_dispatcher');
+    $event = new Sfweb2leadWebformEvent($salesforce_data_object, $this, $webform_submission);
+    $dispatcher->dispatch(Sfweb2leadWebformEvent::SUBMIT, $event);
+    return (array) $salesforce_data_object;

There's no reason to cast $salesforce_data to an object, then back.
It's a property of Sfweb2leadWebformEvent, which will be passed by reference - expose it via setter(s) instead:

+    /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
+    $dispatcher = \Drupal::service('event_dispatcher');
+    $event = new Sfweb2leadWebformEvent($salesforce_data, $this, $webform_submission);
+    $dispatcher->dispatch(Sfweb2leadWebformEvent::SUBMIT, $event);
+    return $event->getData();

And add a typehint to the constructor like so:
+ public function __construct(array $data, SalesforceWebToLeadPostWebformHandler $handler, WebformSubmissionInterface $submission) {

nginex’s picture

Issue tags: +LutskGCW19
nginex’s picture

Assigned: Unassigned » nginex

I'm going to fix the above minor points.

nginex’s picture

Status: Needs work » Needs review
FileSize
1.76 KB
5.15 KB

Here we go

nginex’s picture

Assigned: nginex » Unassigned

  • AaronBauman committed 00fff85 on 8.x-5.x authored by nginex
    Issue #2982152 by John Cook, aaronbauman, nginex: Add data alter hook to...
AaronBauman’s picture

Status: Needs review » Fixed

Thanks for the patch. I've committed a slightly updated version.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.