There is a bug in OgMembership::setRoles() that prevents the roles from being saved when an associative array of roles is passed in. Only when a numerically indexed array of roles is passed in the roles are correctly saved.
The problem is somewhere around FieldItemList::filterEmptyItems() - I did not dig all the way through, but when an associative array is passed the roles are seen as empty.
We should put the call to array_values() in the setRoles() method.
It would also be a good idea to make a test that proves we can pass the result from OgRole::loadMultiple() to OgMembership::setRoles() since this will probably be very commonly used like this.
There is a bug in
OgMembership::setRoles()
that prevents the roles from being saved when an associative array of roles is passed in. Only when a numerically indexed array of roles is passed in the roles are correctly saved.For example this currently fails:
But this works:
The problem is somewhere around
FieldItemList::filterEmptyItems()
- I did not dig all the way through, but when an associative array is passed the roles are seen as empty.We should put the call to
array_values()
in thesetRoles()
method.It would also be a good idea to make a test that proves we can pass the result from
OgRole::loadMultiple()
toOgMembership::setRoles()
since this will probably be very commonly used like this.