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 = '[email protected]';
$message ='Your application has been marked as canceled';
// Send the email.
$params = array(
'subject' => '[Aplication Status] - Application marked as canceled',
'body' => check_markup(
t($message),
'plain_text'
),
);
$mailManager->mail('mailsend', 'completed', $email, $langcode, $params);
//drupal_set_message($entity->id());
}
/**
* {@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?