Problem/Motivation
I've created a custom module to alter the whole workflow.
My module doesn't allow to go from "pending" to "allowed". When I submit the "GroupMembershipApproveForm" then transition is not allowed but the message is "Membership request approved" because the module forgot to validate the transition. (Same for create,reject)
I know this is not possible to happen without custom module, but programmatically validation is missing.
Steps to reproduce
Change the workflow. (Disable to go from "pending" to "allowed")
Request membership
Allow membership
Form message: "Membership request approved"
But state is still pending.
Proposed resolution
Return a bool
public function updateStatus(GroupContentInterface $group_content, $transition_id): bool {
$state_item = $group_content->get(GroupMembershipRequest::STATUS_FIELD)->first();
if ($state_item->isTransitionAllowed($transition_id)) {
$state_item->applyTransitionById($transition_id);
$group_content->set('grequest_updated_by', $this->currentUser->id());
+ return true;
}
+ return false;
}Check it before update
public function approve(GroupContentInterface $group_content, array $group_roles = []) {
$is_updated = $this->updateStatus($group_content, GroupMembershipRequest::TRANSITION_APPROVE);
$result = $is_updated && $group_content->save() == SAVED_UPDATED;
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3298290-4.patch | 1.26 KB | lobsterr |
| #2 | validate_transition_before_save_group_content-3298290-2.patch | 2.52 KB | kecsot |
Comments
Comment #2
kecsotComment #3
kecsotComment #4
lobsterr commentedI think it would a correct way to handle it. I also added a validation for group content
Comment #5
kecsotTested and it works well.
Thank you!
Comment #7
lobsterr commentedThank you for your contribution