drupal_get_form() occasionally returns $membership->uid as an array, this causes errors in MembershipEntityController::save()

Created on 22 June 2015, almost 10 years ago
Updated 14 February 2025, about 2 months ago

Problem/Motivation

I was getting errors like the following:

Illegal offset type in MembershipEntityController->save() (line 111 of sites/all/modules/membership_entity/membership_entity.controller.inc).

... upon further investigation, this was happening because $membership->uid was an array containing the actual UID in the following code:

// Add or remove old roles depending on membership status.
$roles[$membership->uid] = array(
  'rid' => $data['primary_role'],
  'op' => ($membership->status == MEMBERSHIP_ENTITY_ACTIVE) ? 'add' : 'remove',
);

... even more investigation showed that a single integer value goes into the form in membership_entity_join_form()...

$form['#membership_entity'] = membership_entity_create(array(
  'uid' => $GLOBALS['user']->uid,
  'type' => $bundle,
));

... but, when $form_state is built in drupal_get_form(), $form_state['values']['uid'] is an array.

Proposed resolution

I propose we convert $membership->uid to an integer as soon as we can, in membership_entity_edit_form_submit().

Remaining tasks

  1. Add steps to reproduce
  2. Decide if this is the best way to proceed
  3. Review and RTBC
  4. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

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