Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,38 +276,4 @@ access:
- authenticated
users: { }
permissions: { }
handlers:
event_submission_email:
id: email
label: 'Event Submission Email'
handler_id: event_submission_email
status: true
conditions: { }
weight: 0
settings:
states:
- completed
to_mail: contact.dpc@dsdbi.desk-mail.com
to_options: { }
cc_mail: ''
cc_options: { }
bcc_mail: ''
bcc_options: { }
from_mail: contact.dpc@dsdbi.desk-mail.com
from_options: { }
from_name: _default
subject: 'Event Submission'
body: _default
excluded_elements:
agree_privacy_statement: agree_privacy_statement
ignore_access: false
exclude_empty: true
exclude_empty_checkbox: true
html: true
attachments: false
twig: false
debug: false
reply_to: ''
return_path: ''
sender_mail: ''
sender_name: ''
handlers: { }
49 changes: 49 additions & 0 deletions modules/tide_event/tide_event.install
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,52 @@ function tide_event_update_10002() {
])
->save();
}

/**
* Remove outdated email handler from tide_event_submission webform.
*/
function tide_event_update_10003() {
$webform_id = 'tide_event_submission';

// Load the webform entity.
$webform = \Drupal::entityTypeManager()
->getStorage('webform')
->load($webform_id);

if (!$webform) {
return \Drupal::translation()->translate('Webform @id not found.', ['@id' => $webform_id]);
}

// Get the handlers.
$handlers = $webform->getHandlers();
$updated = FALSE;

// Go through each handler.
foreach ($handlers as $handler_id => $handler) {
if ($handler_id == 'event_submission_email') {
$configuration = $handler->getConfiguration();

// Check if this is an email handler with the specific to_mail address.
if (isset($configuration['settings']['to_mail']) &&
$configuration['settings']['to_mail'] === 'contact.dpc@dsdbi.desk-mail.com') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key logic - if the webform is still configured to send an email to this address it should be removed.

// Delete this handler.
$webform->deleteWebformHandler($handler_id);
$updated = TRUE;
}
}
}

if ($updated) {
// Save the updated webform.
$webform->save();
return \Drupal::translation()->translate(
'Removed outdated email handler from @webform webform.',
['@webform' => $webform_id]
);
}

return \Drupal::translation()->translate(
'No handlers with the specified email address were found in @webform webform.',
['@webform' => $webform_id]
);
}