Event Subscriber to alter data before sending to Pardot

Created on 29 April 2022, about 2 years ago
Updated 27 January 2023, over 1 year ago

Problem/Motivation

While using taxonomy reference field on webform instead of sending the taxonomy term ID, requirement is to send term name to Pardot. Need to alter data before sending to Pardot.

Steps to reproduce

Proposed resolution

Created Event and Event Subscriber in Webform_pardot module.
Then Subscribed this Event in custom module and Performed required operations in Data and send back to Pardot Handler.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇮🇳India piyusha_pokharana

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States nathan573

    Thanks for this patch! I've implemented with my custom module and it works!

    Here is my code if it saves anybody some time implementing this. I'm a bit new to Drupal 9 and subscribers so AMATEUR CODE ALERT!

    custom_module/custom_module.services.yml

    services:
      custom_module.pardot_submission_event_subscribe:
        class: Drupal\custom_module\EventSubscribe\PardotSubmissionEventSubscriber
        tags:
          - { name: 'event_subscriber' }
    

    custom_module/src/EventSubscribe/PardotSubmissionEventSubscriber.php

    <?php
    
    namespace Drupal\custom_module\EventSubscribe;
    
    use Drupal\webform_pardot\Event\PardotEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Alters the webform submission data that is submitted to Pardot.
     */
    class PardotSubmissionEventSubscriber implements EventSubscriberInterface {
    
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents(): array {
        return [
          PardotEvent::PARDOT_DATA => 'alterPardotSubmission',
        ];
      }
    
      /**
       * Alter Pardot submission.
       *
       * @param Drupal\custom_module\EventSubscribe\PardotEvent $event
       *   The Pardot event containing the submitted data.
       */
      public function alterPardotSubmission(PardotEvent $event): void {
    
        $webform_data = $event->getData();
    
        // Alter the webform data here.
    
        $event->setData($webform_data );
    
      }
    
    }
    
Production build 0.69.0 2024