The grouping methods within a category have been designed to be plugins.
When a custom plugin is added , the recipients across the grouping methods in a category are not being identified properly.

For example, with the current role grouping method and a custom grouping method based on say user creation date, currently
the code gathers all users with the role AND the users satisfying the user creation date condition.

But what is expected is that users that have the chosen role, whose user creation date satisfies the condition chosen should be gathered,

Also a check needs to be added on the category form that a value has been chosen for atleast one grouping method.

Comments

sukanya.ramakrishnan created an issue. See original summary.

sukanya.ramakrishnan’s picture

Submitting a patch for this issue!

Thanks,
Sukanya

sukanya.ramakrishnan’s picture

Status: Active » Needs review
sukanya.ramakrishnan’s picture

Issue summary: View changes
StatusFileSize
new3.75 KB
new518 bytes

Changed the message when no recipient types are chosen on the category form to a simpler one. Submitting a patch and interdiff from #2

Status: Needs review » Needs work

The last submitted patch, 4: 2885074-multiple-grouping-methods-issue-04.patch, failed testing. View results

jhedstrom’s picture

  1. +++ b/src/Form/CategoryForm.php
    @@ -94,6 +94,25 @@ class CategoryForm extends EntityForm {
    +      $form_state->setErrorByName('', $this->t('Atleast one recipient is required.'), 'error');
    

    Typo here in 'Atleast' :)

  2. +++ b/src/MassContact.php
    @@ -231,10 +231,22 @@ class MassContact implements MassContactInterface {
    +            $category_recipients[$plugin_id] = $this->getAllActiveUsers();
    

    I thought it wasn't possible to create categories without recipients... When it says some other grouping should have categories, then why do we need to select all users here?

sukanya.ramakrishnan’s picture

@jhedstrom. Thanks for your comments.

While it is correct that we cant create categories without recipients, there can be a grouping in a category without any selections.
The getAllActiveUsers() is needed because if we intersect an empty grouping with another grouping with selections, we are going to get an empty resultset.

sukanya.ramakrishnan’s picture

Hmm, now i think a better approach would be to just not add the recipients before doing the intersect, as simple as that.

Will fix that :)

sukanya.ramakrishnan’s picture

Submitting patch based ob jhedstrom's review. Also added a test for the categoryform to ensure that there is atleast one recipient selected.

Thanks,
Sukanya

sukanya.ramakrishnan’s picture

Status: Needs work » Needs review

jhedstrom’s picture

Status: Needs review » Fixed

Awesome! Also, thanks for the test coverage!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.