Support for additional "property_type" values in saveUserinfo

Created on 30 April 2025, 12 days ago
Updated 6 May 2025, 6 days ago

Problem/Motivation

I use the "mobile_number" module ( https://www.drupal.org/project/mobile_number ) to store the phone number field for my users, however that field's property_type is "mobile_number", even though the value itself is a string. As a result, it lands on the default case in the switch statement in saveUserInfo.

Steps to reproduce

-Install mobile_number module
-Add mobile_number field to user info
-Map the new field in opened_connect settings to phone
-Login

Proposed resolution

A generic solution (which I tested and works fine for this specific case), would be to test if the claim_value is a string in the default case of the switch statement and save it as if the property_type was indeed a string. Additional error checking would possibly required as I don't know if other field types might throw an exception if, for example, an improperly formatted string was saved.

There may be a more robust solution involving available field entity iteration and custom mapping, but it would almost certainly be overkill.

Here is the code change I tested in saveUserInfo:

              default:
                // Handle property types added by other modules (such as mobile_phone) if they are strings
                if (is_string($claim_value)) {
                  $account->set($property_name, $claim_value);
                  break;
                }

                $this->logger->error('Could not save user info, property type not implemented: %property_type',
                  ['%property_type' => $property_type]
                );
                break;
Feature request
Status

Active

Version

3.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024