Problem/Motivation

It would be nice to get a count of recipients as the categories field on the mass contact form is updated.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom created an issue. See original summary.

manishsaharan’s picture

Status: Active » Needs review
FileSize
1.76 KB

Now we can check number of users as per role or category during selecting each category

jhedstrom’s picture

This is a great idea! Thanks for the initial patch.

A few comments regarding the implementation:

  1. +++ b/src/Form/MassContactForm.php
    @@ -445,6 +455,26 @@ class MassContactForm extends ContentEntityForm {
    +  *   Ajax callback ¶
    

    Nit pick: Trailing space here, and also this should mention what the callback does :)

  2. +++ b/src/Form/MassContactForm.php
    @@ -445,6 +455,26 @@ class MassContactForm extends ContentEntityForm {
    +  public function countRecipients(array &$form, FormStateInterface $form_state) {
    

    Since there can be non-role-based 'grouping methods', this function will probably need to figure out which plugins are selected, and then call out to each selected plugin for a complete list of UIDs, and then do a count of unique uids returned by all methods.

    Checkout Drupal\mass_contact\Plugins\MassContact\GroupingMethod\Role. We might need to add a new interface or something that defines the ability of a plugin to provide this ability.

  3. +++ b/src/Form/MassContactForm.php
    @@ -445,6 +455,26 @@ class MassContactForm extends ContentEntityForm {
    +        $results = db_query("SELECT COUNT(`roles_target_id`) as `usercount` FROM `user__roles` WHERE `roles_target_id` = '$category'")->fetchAll();
    

    When this logic is moved into the role plugin, it should at the very least use Database::select() instead of a raw SQL query I think.

jhedstrom’s picture

Status: Needs review » Needs work