diff --git a/ginvite.module b/ginvite.module index 566c5580fa8fab82df0329bbb9c5435f4a5839ef..1de1d6cd22558aeaca31dada7801d847c3d02393 100644 --- a/ginvite.module +++ b/ginvite.module @@ -213,7 +213,8 @@ function ginvite_mail($key, &$message, $params) { $group_invite_config = $group_plugin_collection->getConfiguration()['group_invitation']; $language_manager->setConfigOverrideLanguage($original_language); - + $subject = ''; + $body = ''; if ($key == 'cancel') { $subject = $group_invite_config['cancel_user_invitation_subject']; $body = $group_invite_config['cancel_user_invitation_body']; @@ -312,6 +313,7 @@ function ginvite_entity_type_alter(array &$entity_types) { * Implements hook_token_info(). */ function ginvite_token_info() { + $tokens = []; $tokens['register_link'] = [ 'name' => t('Register Link'), 'description' => t('Url to register page with prefilled email address.'), @@ -364,7 +366,7 @@ function ginvite_tokens($type, $tokens, array $data, array $options, BubbleableM * Implements hook_form_FORM_ID_alter(). */ function ginvite_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) { - $invitee_mail = \Drupal::request()->query->get("invitee_mail"); + $invitee_mail = \Drupal::request()->query->get('invitee_mail'); if (isset($invitee_mail)) { $search = ['-', '_']; $replace = ['+', '/']; @@ -410,7 +412,6 @@ function ginvite_cron() { } // Query for all the invites that are expired for this group type. - $config_id = $group_type->getContentPlugin('group_invitation')->getContentTypeConfigId(); $expired_invites = $group_content_storage->getQuery() ->accessCheck(FALSE) diff --git a/src/Controller/InvitationOperations.php b/src/Controller/InvitationOperations.php index 4b359337e83a7262ab43e6a200a2b46b9cb392ee..8c7023ee7e366457ba0049410a3a2d46d57cb14e 100644 --- a/src/Controller/InvitationOperations.php +++ b/src/Controller/InvitationOperations.php @@ -2,21 +2,19 @@ namespace Drupal\ginvite\Controller; +use Drupal\Core\Access\AccessResult; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityFormBuilderInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Url; -use Drupal\Core\Session\AccountInterface; use Drupal\ginvite\Plugin\GroupContentEnabler\GroupInvitation; use Drupal\group\Entity\GroupContent; use Drupal\group\Entity\GroupContentInterface; +use Drupal\group\Entity\GroupInterface; +use Drupal\group\GroupMembershipLoader; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Drupal\Core\Access\AccessResult; -use Drupal\Core\Access\AccessResultInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\group\GroupMembershipLoader; -use Drupal\group\Entity\GroupInterface; /** * Handles Accept/Decline operations and Access check for them. diff --git a/src/Event/InvitationBaseEvent.php b/src/Event/InvitationBaseEvent.php index ee35a1a707030678a4e1351e5ff368d092953111..83bc014b6a9a0e68e9796addfb198ba7fbb1aeb0 100644 --- a/src/Event/InvitationBaseEvent.php +++ b/src/Event/InvitationBaseEvent.php @@ -2,8 +2,8 @@ namespace Drupal\ginvite\Event; -use Drupal\ginvite\GroupInvitation; use Drupal\Component\EventDispatcher\Event; +use Drupal\ginvite\GroupInvitation; /** * Base invitation event. diff --git a/src/EventSubscriber/GinviteSubscriber.php b/src/EventSubscriber/GinviteSubscriber.php index 315085aea3ac0a0e0b06c05f9344b743f596914f..bbbbb659a1e75be8a5a505ce442af0940274cb9b 100644 --- a/src/EventSubscriber/GinviteSubscriber.php +++ b/src/EventSubscriber/GinviteSubscriber.php @@ -4,15 +4,15 @@ namespace Drupal\ginvite\EventSubscriber; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\ginvite\Event\InvitationBaseEvent; use Drupal\ginvite\Event\UserLoginWithInvitationEvent; -use Drupal\ginvite\GroupInvitationLoader; use Drupal\ginvite\Event\UserRegisteredFromInvitationEvent; +use Drupal\ginvite\GroupInvitationLoader; use Drupal\ginvite\Plugin\GroupContentEnabler\GroupInvitation; use Drupal\group\Entity\GroupContent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -78,11 +78,11 @@ class GinviteSubscriber implements EventSubscriberInterface { * The config factory. */ public function __construct( - GroupInvitationLoader $invitation_loader, - AccountInterface $current_user, - MessengerInterface $messenger, + GroupInvitationLoader $invitation_loader, + AccountInterface $current_user, + MessengerInterface $messenger, LoggerChannelFactoryInterface $logger_factory, - ConfigFactoryInterface $config_factory + ConfigFactoryInterface $config_factory ) { $this->groupInvitationLoader = $invitation_loader; $this->currentUser = $current_user; @@ -158,7 +158,7 @@ class GinviteSubscriber implements EventSubscriberInterface { } /** - * Auto Accept Group Invitations from the ginvite module + * Auto Accept Group Invitations from the ginvite module. * * @param \Drupal\ginvite\Event\UserRegisteredFromInvitationEvent $event * The UserRegisteredFromInvitationEvent to process. diff --git a/src/Form/BulkGroupInvitation.php b/src/Form/BulkGroupInvitation.php index 3a54d158cdf7b0e6bdbfe8f33769068828638852..b4bbf95269b942f6e4825bbd71a7207d69ec29ab 100644 --- a/src/Form/BulkGroupInvitation.php +++ b/src/Form/BulkGroupInvitation.php @@ -55,7 +55,6 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac */ protected $messenger; - /** * Group. * @@ -63,6 +62,20 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac */ protected $group; + /** + * The group membership loader. + * + * @var \Drupal\group\GroupMembershipLoaderInterface + */ + protected $groupMembershipLoader; + + /** + * Group invitations loader. + * + * @var \Drupal\ginvite\GroupInvitationLoader + */ + protected $groupInvitationLoader; + /** * Constructs a new BulkGroupInvitation Form. * @@ -169,7 +182,7 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - foreach ($form_state->getValues() as $key => $value) { + foreach (array_keys($form_state->getValues()) as $key) { switch ($key) { case 'email_address': @@ -189,6 +202,7 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac public function submitForm(array &$form, FormStateInterface $form_state) { // Prepare params to store them in tempstore. + $params = []; $params['gid'] = $this->group->id(); $params['plugin'] = $this->group->getGroupType()->getContentPlugin('group_invitation')->getContentTypeConfigId(); $params['emails'] = $this->getSubmittedEmails($form_state); @@ -234,8 +248,8 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac } if (!empty($invalid_emails)) { - $message_singular = "The @error_message is not a valid e-mail address."; - $message_plural = "The e-mails: @error_message are not valid e-mail addresses."; + $message_singular = 'The @error_message is not a valid e-mail address.'; + $message_plural = 'The e-mails: @error_message are not valid e-mail addresses.'; $this->displayErrorMessage($invalid_emails, $message_singular, $message_plural, $form_state); } @@ -259,8 +273,8 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac } if (!empty($invalid_emails)) { - $message_singular = "User with @error_message e-mail already a member of this group."; - $message_plural = "Users with: @error_message e-mails already members of this group."; + $message_singular = 'User with @error_message e-mail already a member of this group.'; + $message_plural = 'Users with: @error_message e-mails already members of this group.'; $this->displayErrorMessage($invalid_emails, $message_singular, $message_plural, $form_state); } @@ -282,8 +296,8 @@ class BulkGroupInvitation extends FormBase implements ContainerInjectionInterfac } if (!empty($invalid_emails)) { - $message_singular = "Invitation to @error_message already sent."; - $message_plural = "Invitations to: @error_message already sent."; + $message_singular = 'Invitation to @error_message already sent.'; + $message_plural = 'Invitations to: @error_message already sent.'; $this->displayErrorMessage($invalid_emails, $message_singular, $message_plural, $form_state); } diff --git a/src/Form/BulkGroupInvitationConfirm.php b/src/Form/BulkGroupInvitationConfirm.php index a3d7874bca9210b42baa470f62e20ab712b945c9..1f26552ba63bd4731684b1013faffcc033abe9bc 100644 --- a/src/Form/BulkGroupInvitationConfirm.php +++ b/src/Form/BulkGroupInvitationConfirm.php @@ -114,12 +114,12 @@ class BulkGroupInvitationConfirm extends ConfirmFormBase implements ContainerInj */ public function getDescription() { - $email_list_markup = ""; + $email_list_markup = ''; foreach ($this->tempstore['emails'] as $email) { $email_list_markup .= "{$email} <br />"; } - $description = $this->t("Invitation recipients: <br /> @email_list", + $description = $this->t('Invitation recipients: <br /> @email_list', [ '@email_list' => new FormattableMarkup($email_list_markup, []), ] diff --git a/src/GroupInvitation.php b/src/GroupInvitation.php index fce4ba963d4e8e0483144e6e1e703579b1e151f3..ea229ea392d8ad2b6a1c3444c22d7baf5138136e 100644 --- a/src/GroupInvitation.php +++ b/src/GroupInvitation.php @@ -69,18 +69,6 @@ class GroupInvitation implements CacheableDependencyInterface { return $this->groupContent->getEntity(); } - /** - * Returns the group roles for the invitation. - * - * @return \Drupal\group\Entity\GroupRoleInterface[] - * An array of group roles, keyed by their ID. - */ - public function getRoles() { - /** @var \Drupal\group\Entity\Storage\GroupRoleStorageInterface $group_role_storage */ - $group_role_storage = \Drupal::entityTypeManager()->getStorage('group_role'); - return $group_role_storage->loadByUserAndGroup($this->getUser(), $this->getGroup()); - } - /** * {@inheritdoc} */ diff --git a/src/GroupInvitationLoader.php b/src/GroupInvitationLoader.php index 8ef1e660f141f17dfb1630aac55c8138dd0fe7a7..6bcb3fa7329657a55290bfb7a8ba9f3952e90c22 100644 --- a/src/GroupInvitationLoader.php +++ b/src/GroupInvitationLoader.php @@ -4,9 +4,9 @@ namespace Drupal\ginvite; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\group\Entity\GroupInterface; -use Drupal\ginvite\Plugin\GroupContentEnabler\GroupInvitation; use Drupal\ginvite\GroupInvitation as GroupInvitationWrapper; +use Drupal\ginvite\Plugin\GroupContentEnabler\GroupInvitation; +use Drupal\group\Entity\GroupInterface; /** * Loader for wrapped GroupContent entities using the 'group_invitation' plugin. diff --git a/src/GroupInvitationLoaderInterface.php b/src/GroupInvitationLoaderInterface.php index 42341074e60dbedf6452865004846cc77f062299..bc8802a71cebdecefcb2cd8673658d49328ec99d 100644 --- a/src/GroupInvitationLoaderInterface.php +++ b/src/GroupInvitationLoaderInterface.php @@ -3,8 +3,8 @@ namespace Drupal\ginvite; use Drupal\Core\Session\AccountInterface; -use Drupal\group\Entity\GroupInterface; use Drupal\ginvite\Plugin\GroupContentEnabler\GroupInvitation; +use Drupal\group\Entity\GroupInterface; /** * Defines the group invitation loader interface. diff --git a/src/Plugin/GroupContentEnabler/GroupInvitation.php b/src/Plugin/GroupContentEnabler/GroupInvitation.php index 6db08f5d2cfdb0901a54832f069f3eb1681a473f..f5bf93b32dcfc8ac4569168833413e4be59a99e8 100644 --- a/src/Plugin/GroupContentEnabler/GroupInvitation.php +++ b/src/Plugin/GroupContentEnabler/GroupInvitation.php @@ -2,16 +2,16 @@ namespace Drupal\ginvite\Plugin\GroupContentEnabler; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\group\Access\GroupAccessResult; +use Drupal\group\Entity\GroupContentInterface; use Drupal\group\Entity\GroupInterface; use Drupal\group\Plugin\GroupContentEnablerBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\group\Entity\GroupContentInterface; -use Drupal\group\Access\GroupAccessResult; -use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/tests/src/Functional/GroupInviteExpireTest.php b/tests/src/Functional/GroupInviteExpireTest.php index d8bd27e15a44267d254d47f18aefdb0fc1448c5f..95afd958928ea55556b73e581c70abfcc0e0053b 100644 --- a/tests/src/Functional/GroupInviteExpireTest.php +++ b/tests/src/Functional/GroupInviteExpireTest.php @@ -18,7 +18,7 @@ class GroupInviteExpireTest extends GroupBrowserTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'group', 'group_test_config', 'ginvite', diff --git a/tests/src/Functional/GroupInviteTest.php b/tests/src/Functional/GroupInviteTest.php index 930e79c8278dc63e38d03b3177fc008ce7ef14e8..4ed0f04511609e9a643b2beab857daf820acab01 100644 --- a/tests/src/Functional/GroupInviteTest.php +++ b/tests/src/Functional/GroupInviteTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\ginvite\Functional; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\group\Entity\GroupContent; use Drupal\Tests\group\Functional\GroupBrowserTestBase; /** @@ -18,7 +17,7 @@ class GroupInviteTest extends GroupBrowserTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'group', 'group_test_config', 'ginvite', @@ -108,7 +107,8 @@ class GroupInviteTest extends GroupBrowserTestBase { $role->grantPermissions(['administer members']); $role->save(); - // Verify the normal member without the permission cannot add roles to users on invite. + // Verify the normal member without the permission cannot add roles + // to users on invite. $this->drupalGet('/group/1/content/add/group_invitation'); $this->assertSession()->fieldExists('group_roles[default-custom]'); }