Contact::jsonSerialize() has wrong logic

Created on 25 October 2023, about 1 year ago
Updated 27 February 2024, 10 months ago

Problem/Motivation

The Contact::jsonSerialize() method converts the Contact object into an array. But it doesn't include all properties and it doesn't include empty fields which should be reflected in json as well.
The jsonSerialize is currently used to create an array with parts of a Contact so it can be submitted to the Flexmail API to update (replace) a contact. The latter only accepts a full contact object during an update (replace via PUT) call. Side note: there is also a partly update (PATCH) api call which isn't implemented in this module.

Other issues with Contact:
The constructor accepts a source as int or null, but the source property is defined as int only.
A contact object has several fields that can never be empty, which is currently allowed:

  • email
  • language
  • source

Proposed resolution

Implement a correct Contact::jsonSerialize() returning all properties, also empty ones.
If the jsonSerialize isn't useful anymore after this change, we can add a Contact::toArray() method which the API manager can use to convert a Contact object to an array and eliminate the disallowed Contact fields during an updateContact API call.

Remaining tasks

Revise the Contact class and FlexmailApiManager:

  1. Fix the constructor
  2. Fix properties
  3. Remove jsonSerialize() in favour of toArray()
  4. Alter FlexmailApiManager::updateContact() so it filters out the disallowed contact fields before calling the API.
  5. Make Contact implement ValueInterface and extend from ValueBase as introduced in #3394527 📌 Add support for "Interest" endpoints, deprecate "Interest label" endpoints Fixed
  6. Adjust the flexmail_webform module according to these changes.

User interface changes

None.

API changes

FlexmailApiManager::updateContact() will accept a full Contact object and process it according to the call it's making.

Data model changes

None.

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium fernly

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

Comments & Activities

Production build 0.71.5 2024