RecipientHandlerSubscribersByRole.php in Simplenews 3.x
File
modules/simplenews_demo/src/Plugin/simplenews/RecipientHandler/RecipientHandlerSubscribersByRole.php
View source
<?php
namespace Drupal\simplenews_demo\Plugin\simplenews\RecipientHandler;
use Drupal\simplenews\SubscriberInterface;
use Drupal\simplenews\Plugin\simplenews\RecipientHandler\RecipientHandlerEntityBase;
class RecipientHandlerSubscribersByRole extends RecipientHandlerEntityBase {
public function settingsForm() {
$roles = array_map([
'\\Drupal\\Component\\Utility\\Html',
'escape',
], user_role_names(TRUE));
$element['role'] = [
'#type' => 'select',
'#title' => t('Role'),
'#default_value' => $this->configuration['role'] ?? NULL,
'#options' => $roles,
];
return $element;
}
protected function buildEntityQuery() {
return \Drupal::entityQuery('simplenews_subscriber')
->condition('status', SubscriberInterface::ACTIVE)
->condition('subscriptions', $this
->getNewsletterId())
->condition('subscriptions.status', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED)
->condition('uid.entity.roles', $this->configuration['role']);
}
}