Integration of User Registration with Constant Contact List Subscription

Created on 14 August 2024, 4 months ago
Updated 3 September 2024, 4 months ago

Feature Request

After the submission of this issue I wanted to update with an potential path to incorporating this functionality into the module.
Add mapping of other fields on user registration form.
This would require modification of the field type /src/Plugin/Field/FieldType/ConstantContactListItem.php and adding additional field mapping settings (other than just the email address) and probably modification to _ik_constant_contact_entity_subscribe_on_save to set the other additional fields.

Original Issue

1. We have implemented a feature to subscribe new users to a Constant Contact list upon registration. To achieve this, we have made the following modifications:

2. Added a 'Signup List' field of type 'Constant Contact Lists' to the 'Create new account' form at /user/register.
Incorporated additional fields that correspond to Constant Contact's available fields:

  • field_first_name
  • field_last_name
  • field_company_name
  • field_job_title
  • field_street
  • field_city
  • field_state
  • field_postal_code
  • field_country

However, we've encountered an issue: upon form submission, only the email address is being added to the new contact in Constant Contact.

We are seeking guidance on how to properly map the above fields from the registration form to their respective fields in Constant Contact.

We have observed that using the 'General Interest Signup Block' successfully adds the data to the new contact in Constant Contact. However, this method does not store the information under the User entity in our system.

We would greatly appreciate any advice on how to resolve this issue, ensuring that all relevant user data is both stored in our system and successfully transmitted to Constant Contact.

Thank you for your assistance in this matter.

✨ Feature request
Status

Needs review

Version

4.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States alexi721

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

Merge Requests

Comments & Activities

  • Issue created by @alexi721
  • πŸ‡ΊπŸ‡ΈUnited States rosemarystanley

    Hello and thanks for reaching out. I will try to take a closer look as soon as I can.

    A couple of suggestions on what you can look at in the meantime:

    There are hooks that fire before sending user data to constant contact. This one could be helpful:
    hook_ik_constant_contact_contact_data_alter details can be found in ik_constant_contact.api.php

    That may be a little more complicated but could be useful.

    The email address from an entity is mapped via field settings in Drupal\ik_constant_contact\Plugin\Field\FieldType\ConstantContactListItem
    Likely this file may need to be modified to map the other user/entity fields.

    I'll take a look as soon as I am able.
    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States alexi721

    Hi Rosemary:

    I will look at both files and use them as guide on how to add additional fields.

    Thank you very much for your quick reply,
    Alex

  • πŸ‡ΊπŸ‡ΈUnited States alexi721

    Hi Rosemary:

    Using 'hook_ik_constant_contact_contact_data_alter' I am able to get the fields first_name, last_name, company_name, job_title, phone_number on CC populated.
    However, none of the 'street_address' field get inserted.

    Could you please provide an example? Below is my code:

    $body->street_address[] = (object) [
        'street' => $data['street'],  
        'city' => $data['city'], 
        'state' => $data['state'], 
        'postal_code' => $data['postal_code'], 
        'country' => $data['country'],
      ];
    

    Thank you for your time and consideration.

  • πŸ‡ΊπŸ‡ΈUnited States rosemarystanley

    The line should actually should be

    
    $body->street_address = (object) [
        'street' => $data['street'],  
        'city' => $data['city'], 
        'state' => $data['state'], 
        'postal_code' => $data['postal_code'], 
        'country' => $data['country'],
      ];
    

    I think that's the issue

  • πŸ‡ΊπŸ‡ΈUnited States alexi721

    Hi Rosemary:

    Removing the brackets fixed the issue and the 'street_address' fields get populated now on Constant Contact.

    For developers who also prefer to utilize the Drupal's Register form and want the custom account fields added to the $data array (my field names are listed above in the text of the ticket), the following assignments were added below line #223: '$fieldMapping = $fieldDefinition->getSetting('field_mapping');' of v3.1.9 of this module:

            $fieldMapping['first_name'] = 'field_first_name';
            $fieldMapping['last_name'] = 'field_last_name';
            $fieldMapping['company_name'] = 'field_organization';
            $fieldMapping['job_title'] = 'field_job_title';
            $fieldMapping['phone_number'] = 'field_phone';
            $fieldMapping['street'] = 'field_address';
            $fieldMapping['city'] = 'field_city';
            $fieldMapping['state'] = 'field_state_or_province';
            $fieldMapping['postal_code'] = 'field_zip_or_postal_code';
            $fieldMapping['country'] = 'field_country';
    

    The fields first_name, last_name, company_name, job_title and phone_number get inserted without extra code.

    For the remaining fields I added the following code to the end of the 'ik_constant_contact.module' file:

    /**
     * Integration of User Registration with Constant Contact List Subscription
     */
    function ik_constant_contact_ik_constant_contact_contact_data_alter(array $data, object &$body) {
      // Ensure the street_address property exists
      if (!isset($body->street_address)) {
        $body->street_address = [];
      }
    
      // Populate the street_address with data from the $data array
      $body->street_address = (object) [
        'street' => $data['street'],
        'city' => $data['city'],
        'state' => $data['state'],
        'postal_code' => $data['postal_code'],
        'country' => $data['country']
      ];
    }
    
  • Assigned to rosemarystanley
  • πŸ‡ΊπŸ‡ΈUnited States rosemarystanley

    That's great. I am going to keep this open for now as a feature request because I'd like to integrate this as an option with the User registration form.

  • πŸ‡ΊπŸ‡ΈUnited States rosemarystanley
  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States rosemarystanley

    Ok created a merge request with some changes to integrate the entity save and mapping of other CC fields. I have no added custom field support yet but thought this might be a good start. Feel free to give it a try.

Production build 0.71.5 2024