protected function D7Webform::buildEmailHandlers in Webform: Migrate 8
Same name and namespace in other branches
- 8.2 src/Plugin/migrate/source/d7/D7Webform.php \Drupal\webform_migrate\Plugin\migrate\source\d7\D7Webform::buildEmailHandlers()
Build email handlers from webform emails table.
1 call to D7Webform::buildEmailHandlers()
- D7Webform::prepareRow in src/
Plugin/ migrate/ source/ d7/ D7Webform.php - Adds additional data to the row.
File
- src/
Plugin/ migrate/ source/ d7/ D7Webform.php, line 726
Class
- D7Webform
- Drupal 7 webform source from database.
Namespace
Drupal\webform_migrate\Plugin\migrate\source\d7Code
protected function buildEmailHandlers($nid, $xref) {
$query = $this
->select('webform_emails', 'we');
$query
->fields('we', [
'nid',
'eid',
'email',
'subject',
'from_name',
'from_address',
'template',
'excluded_components',
'html',
'attachments',
]);
$emails = $query
->condition('nid', $nid)
->execute();
$handlers = [];
foreach ($emails as $email) {
$id = 'email_' . $email['eid'];
foreach ([
'email',
'subject',
'from_name',
'from_address',
] as $field) {
if (!empty($email[$field]) && is_numeric($email[$field]) && !empty($xref[$email[$field]])) {
$email[$field] = "[webform_submission:values:{$xref[$email[$field]]}:raw]";
}
}
$excluded = [];
if (!empty($email['excluded_components'])) {
$excludes = explode(',', $email['excluded_components']);
foreach ($excludes as $exclude) {
if (!empty($xref[$exclude])) {
$excluded[$xref[$exclude]] = $xref[$exclude];
}
}
}
$handlers[$id] = [
'id' => 'email',
'label' => 'Email ' . $email['eid'],
'handler_id' => $id,
'status' => 1,
'weight' => $email['eid'],
'settings' => [
'to_mail' => $email['email'],
'from_mail' => $email['from_address'],
'from_name' => $email['from_name'],
'subject' => $email['subject'],
'body' => str_replace('[submission:', '[webform_submission:', $email['template']),
'html' => $email['html'],
'attachments' => $email['attachments'],
'excluded_elements' => $excluded,
],
];
}
return $handlers;
}