Commit 1d9c97c2 authored by Nikolay Lobachev's avatar Nikolay Lobachev Committed by Nikolay Lobachev
Browse files

Issue #3298290 by kecsot, LOBsTerr: Validate Transition before update the group content

parent 3b0ec251
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\grequest;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\grequest\Plugin\GroupContentEnabler\GroupMembershipRequest;
@@ -120,11 +121,17 @@ class MembershipRequestManager {
   *   Transition approve | reject.
   */
  public function updateStatus(GroupContentInterface $group_content, $transition_id) {
    if ($group_content->getContentPlugin()->getPluginId() != 'group_membership_request') {
      throw new \Exception('Only group content of "Group membership request" is allowed.');
    }
    $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());
    }
    else {
      throw new \Exception(new FormattableMarkup('Transition ":transition_id" is not allowed.', [':transition_id' => $transition_id]));
    }
  }

  /**