amitaibu / og

A fork to work on OG8
https://github.com/Gizra/og
29 stars 16 forks source link

Cannot re-save OgRole #275

Closed amitaibu closed 8 years ago

amitaibu commented 8 years ago

While working on #274 I saw an error trying to re-save an OgRole. Steps to reproduce is using the helper method from #274:

// Make node-page a group.
Og::groupManager()->addGroup('node', 'page');

// Get non-member role.
$role = Og::getRole('node', 'page', OgRoleInterface::ANONYMOUS);

// Add permission and try to save.
$role->grantPermission('subscribe')
    ->save();

We get the error: Drupal\og\Exception\OgRoleException: The id cannot be changed. from og/src/Entity/OgRole.php:258

/cc @pfrenssen

amitaibu commented 8 years ago

@pfrenssen Seems that OgRole::set() is always called from \Drupal\Core\Config\Entity\ConfigEntityStorage::doSave, so we shouldn't throw an exception. Not a perfect solution, but we can simply return early without doing any change. Sounds ok?

amitaibu commented 8 years ago

actually, maybe we can check if the value has changed, and then throw an exception. I'll check..

amitaibu commented 8 years ago

Closed in favor of #278