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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexi721 created an issue. See original summary.

rosemaryreilman’s picture

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!

alexi721’s picture

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, which I really appreciated.
Alex

alexi721’s picture

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. I verified the $data object has all the correct field names and values.

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.

rosemaryreilman’s picture

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

alexi721’s picture

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) {
  // 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']
  ];
}
rosemaryreilman’s picture

Component: Documentation » Code
Assigned: Unassigned » rosemaryreilman
Category: Task » Feature request

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.

rosemaryreilman’s picture

Issue summary: View changes

rosemaryreilman’s picture

Version: 3.1.9 » 4.1.0-alpha1
Status: Active » Needs review

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.

  • rosemaryreilman committed 0c53a280 on 4.x
    Issue #3468149: Integration of User Registration with Constant Contact...
rosemaryreilman’s picture

Status: Needs review » Fixed

Issue has been inactive for 4 months. I'm going to merge the code into 4.x branch and create an alpha2 release.

rosemaryreilman’s picture

Status: Fixed » Closed (fixed)