Commit 0997a323 authored by Siva Karthik Reddy Papudippu's avatar Siva Karthik Reddy Papudippu
Browse files

Issue #3152193 by sivakarthik229: Drupal 9 compatibility fixes

parent 1185ec58
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
name: Group Bulk Operations
type: module
description: Perform bulk actions on groups via views
core: 8.x
core_version_requirement: ^9
package: Group
dependencies:
  - group:group
  - drupal:group
+20 −8
Original line number Diff line number Diff line
@@ -7,9 +7,9 @@ use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Session\AccountInterface;

/**
 * Provides a group multiple role assignment configure form.
@@ -37,6 +37,13 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
   */
  protected $entityTypemanager;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * Constructs a DeleteMultiple form object.
   *
@@ -44,11 +51,15 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
   *   The tempstore factory.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user.
   */
  public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager) {
  public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user) {
    $this->tempStoreFactory = $temp_store_factory;
    $this->entityTypemanager = $entity_type_manager;
    $this->storage = $entity_type_manager->getStorage('group');
    $this->storage = $this->entityTypemanager->getStorage('group');
    $this->user = $this->entityTypemanager->getStorage('user');
    $this->currentUser = $current_user;
  }

  /**
@@ -57,7 +68,8 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('tempstore.private'),
      $container->get('entity_type.manager')
      $container->get('entity_type.manager'),
      $container->get('current_user')
    );
  }

@@ -93,7 +105,7 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $this->groupInfo = $this->tempStoreFactory->get('group_bulk_operations_multiple_group_assign_role_configure')->get(\Drupal::currentUser()->id());
    $this->groupInfo = $this->tempStoreFactory->get('group_bulk_operations_multiple_group_assign_role_configure')->get($this->currentUser->id());
    if (empty($this->groupInfo)) {
      return new RedirectResponse($this->getCancelUrl()->setAbsolute()->toString());
    }
@@ -149,7 +161,7 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
    if ($form_state->getValue('confirm') && !empty($this->groupInfo)) {
      $groups = $this->storage->loadMultiple(array_keys($this->groupInfo));

      $user = User::load($form_state->getValue('user'));
      $user = $this->user->load($form_state->getValue('user'));
      $roles = [];

      foreach ($form_state->getValue('group_roles') as $role) {
@@ -172,7 +184,7 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
          ];
        }
        $batch = [
          'title' => $this->t('Adding @user to Groups', ['@user' => $user->getUsername()]),
          'title' => $this->t('Adding @user to Groups', ['@user' => $user->getDisplayName()]),
          'operations' => $operations,
          'finished' => 'group_bulk_operations_batch_add_member_finished',
        ];
@@ -180,7 +192,7 @@ class AssignGroupRoleMultiple extends ConfirmFormBase {
        batch_set($batch);
      }

      $this->tempStoreFactory->get('group_bulk_operations_multiple_group_assign_role_configure')->delete(\Drupal::currentUser()->id());
      $this->tempStoreFactory->get('group_bulk_operations_multiple_group_assign_role_configure')->delete($this->currentUser->id());
    }
    $form_state->setRedirect('entity.group.collection');
  }