protected function RecipientHandlerBase::addArrayToSpool in Simplenews 8.2
Same name and namespace in other branches
- 3.x src/Plugin/simplenews/RecipientHandler/RecipientHandlerBase.php \Drupal\simplenews\Plugin\simplenews\RecipientHandler\RecipientHandlerBase::addArrayToSpool()
Adds an array of entries to the spool.
The caller specifies the values for a field to define the recipient. The other fields are automatically defaulted based on the issue and newsletter.
Parameters
string $field: Field to set: 'snid', 'data' (automatically serialised) or 'uid' (automatically stored in 'data' array with key 'uid').
array $values: Values to set for field.
2 calls to RecipientHandlerBase::addArrayToSpool()
- RecipientHandlerEntityBase::addToSpool in src/
Plugin/ simplenews/ RecipientHandler/ RecipientHandlerEntityBase.php - Adds a newsletter issue to the mail spool.
- RecipientHandlerSiteMail::addToSpool in modules/
simplenews_demo/ src/ Plugin/ simplenews/ RecipientHandler/ RecipientHandlerSiteMail.php - Adds a newsletter issue to the mail spool.
File
- src/
Plugin/ simplenews/ RecipientHandler/ RecipientHandlerBase.php, line 129
Class
- RecipientHandlerBase
- Base class for all Recipient Handler classes.
Namespace
Drupal\simplenews\Plugin\simplenews\RecipientHandlerCode
protected function addArrayToSpool($field, array $values) {
if (empty($values)) {
return;
}
$template = [
'entity_type' => $this->issue
->getEntityTypeId(),
'entity_id' => $this->issue
->id(),
'status' => SpoolStorageInterface::STATUS_PENDING,
'timestamp' => REQUEST_TIME,
'newsletter_id' => $this
->getNewsletterId(),
];
if ($field == 'uid') {
$field = 'data';
$values = array_map(function ($v) {
return [
'uid' => $v,
];
}, $values);
}
$insert = $this->connection
->insert('simplenews_mail_spool')
->fields(array_merge(array_keys($template), [
$field,
]));
foreach ($values as $value) {
$row = $template;
$row[$field] = $field == 'data' ? serialize($value) : $value;
$insert
->values($row);
}
$insert
->execute();
}