I have a view where the webform submissions of the site authenticated users are shown. In that view I have some bulk operations (created by me) that change the value of a field in these submissions (e.g. status). My question is how a mass email can be send to the users that made an application when the admin change the status in selected submissions?

Here is my custom code for the status update (I sent a test email to my self):

namespace Drupal\webformbulk\Plugin\Action;

use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;

* Push term in front.
* @Action(
*   id = "cancel_submission",
*   label = @Translation("Cancel submissions"),
*   type = "webform_submission"
* )
class CancelSubmission extends ActionBase {

 * {@inheritdoc}
 public function execute($entity = NULL) {
/** @var \Drupal\webform\WebformSubmissionInterface  $entity */

  // Modify submission values
  $entity->setElementData('status', 'canceled')->save();

  //call the email method
  $mailManager = \Drupal::service('plugin.manager.mail');
  $langcode = 'el';

  $email = 'test@hotmai.com';

  $message ='Your application has been marked as canceled';
  // Send the email.
  $params = array(
    'subject' => '[Aplication Status] - Application marked as canceled',
    'body' => check_markup(

$mailManager->mail('mailsend', 'completed', $email, $langcode, $params);

 * {@inheritdoc}
  public function access($object, AccountInterface $account = NULL, 
  $return_as_object = FALSE) {
  /** @var \Drupal\webform\WebformSubmissionInterface $object */
  $result = $object->locked->access('edit', $account, TRUE)
  ->andIf($object->access('update', $account, TRUE));

  return $return_as_object ? $result : $result->isAllowed();


I thought to use the Rules modules but unfortunately I can't find how I can use it, plus I have some doubt about sending a mass email from Rules. Would be reasonable to some other module as views send or the mailchimp module? Is there an API I can use?

  • 2
    Look at VBO as a form. Then use hook form alter to add another submit handler where you get the selected user IDs, load the user, get their emails. Regarding mass mail you probably have to implement batch API or some other solution that sends them chunk by chunk to prevent being blocklisted as spammer.
    – leymannx
    Jan 14 '20 at 7:08
  • @leymannx thanks for your quick reply. By saying 'Look at VBO as form' you mean to create a custom module that alters the VBO form? Actually is not VBO module but rather a custom module that bulk updates the webform submissions. Jan 14 '20 at 8:02
  • Ah I was misguided by the initial title and tags regarding VBO. But doesn't a custom action include a form as well?
    – leymannx
    Jan 14 '20 at 10:16
  • Yes it does. I can make the hook_form_alter but I cant get access to the selected rows values or at least to their sid... Any idea how can I manage this? Jan 14 '20 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.