Related term string pushValue is an array when a string is expected.

Created on 3 April 2024, 16 days ago


drupal/core-recommended: 10.0.11
drupal/salesforce: 5.0.4

I am getting an unexpected type error at L253 of SalesforceMappingFieldPluginBase.php:

    if (!empty($value) && $field_definition['length'] > 0 && mb_strlen($value) > $field_definition['length']) {
      $value = mb_substr($value, 0, $field_definition['length']);

Steps to reproduce

  1. Create a taxonomy and add an entity reference field to another entity (cardinality: 1).
  2. Create a mapping between a Salesforce string and the taxonomy reference field (using the Related Term String mapping field).
  3. Make changes on the Drupal entity to trigger a push to Salesforce.

This will result in an unexpected type error, as mb_strlen() expects a string, but the value is an array.

Proposed resolution

Add an is_string() check to L253, or convert all arrays to strings. I have opted for the latter in my patch, as it seems the expected value should always be a string.

It might also be helpful to add an optional $value parameter to the pushValue function and use it if not empty. This way child classes can alter the value before running the parent class.

Remaining tasks

Someone more familiar with the code to review and improve my patch as it feels too straightforward.

🐛 Bug report






Created by

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

Comments & Activities

Production build 0.62.1