- 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 inik_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.
- Merge request !6Issue #3468149 by alexi721, rosemaryreilman: Integration of User Registration... β (Open) created by Unnamed author
- Status changed to Needs review
4 months ago 1:40pm 3 September 2024 - πΊπΈ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.