Cannot re-save OgRole
Closed this issue · 3 comments
amitaibu commented
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
@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
actually, maybe we can check if the value has changed, and then throw an exception. I'll check..