I would link to add an extra mail configuration to the existing mail config.
I'v done this in my custom module with the hook_form_alter() :

function webforms_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id === 'webform_email_edit_form') {
    $node = $form['#node'];
  
    // Add the checkbox to disable the email for current recipients.
    $form['extra']['resend_up_del'] = array(
      '#title' => t('Resend mail by submission update/delete'),
      '#description' => t('Check to enable resend this mailing when a submission is updated/deleted. The subject will be prefixed by UPDATE or DELETE'),
      '#type' => 'checkbox',
      '#default_value' => $node->webform['emails'][$form['eid']['#value']]['extra']['resend_up_del'],
    );
    return $form;
  }
}

I changed the function webform_email_edit_form_submit() in webform.emails.inc so this extra config will be saved within the webform node (Patch included) and can be used within the hooks when a submission is updated and deleted.

Is this the way to go ?
Could it be a feature ?

Comments

pbosmans created an issue. See original summary.

danchadwick’s picture

Status: Active » Fixed

This seems like a reasonable strategy.

Instead of hacking webform, install your own submit handler into the form to save the extra settings. They will be saved to the database (I think). I'm not sure what else "extra" is used for without reading the code.

No, I don't see this going into webform, especially with Drupal hooks make it reasonable to accomplish without modifying webform itself.

pbosmans’s picture

I tried that but couldn't accomplish what i wanted.
Put my settings into the webform so it will be saved into the webform_emails table.
This table have an extra field that is 'A serialized array of additional options for the e-mail configuration, including value mapping for the TO and FROM addresses for select lists.'

But with the current setup webform.emails.inc creates an empty extra array, so there is no possibility to add 'additional options' to it.

I appreciate any other suggestions to accomplish my needs.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dobe’s picture

Category: Support request » Feature request
Status: Closed (fixed) » Needs review

@DanChadwick
I was looking at doing the same thing. Extra is used to store the "Email components" and other things according to the column description.

The rest of webform allows you to modify the form and submit the data the way you describe through hooks (and update the extra column). The issue with the email hook is that the "$email" variable gets created and submitted to database in the same submit handler. Giving no way to modify. In addition the only way that "extra" gets into the variable is through here:

<?php
/**
 * Submit handler for webform_email_edit_form().
 */
function webform_email_edit_form_submit($form, &$form_state) {
  // Ensure a webform record exists.
  $node = $form['#node'];
  webform_ensure_record($node);

  // Remove duplicate email To: addresses.
  $form_state['values']['email_custom'] = implode(',', array_unique(array_map('trim', explode(',', $form_state['values']['email_custom']))));

  // Merge the e-mail, name, address, and subject options into single values.
  $email = array(
    'eid' => $form_state['values']['eid'],
    'nid' => $node->nid,
  );

  foreach (array('email', 'from_name', 'from_address', 'subject') as $field) {
    $option = $form_state['values'][$field . '_option'];
    if ($option == 'default') {
      $email[$field] = 'default';
    }
    else {
      $email[$field] = $form_state['values'][$field . '_' . $option];

      // Merge the email mapping(s) into single value(s)
      $cid = $form_state['values'][$field . '_' . $option];
      if (is_numeric($cid) && isset($form_state['values'][$field . '_mapping'][$cid])) {
        $email['extra'][$field . '_mapping'] = $form_state['values'][$field . '_mapping'][$cid]; <--- only place extra gets built!!!!!!!!!!!!
      }
    }
  }
...........
}
?>

So the only way that you can really get your data in is to have a module declare a submit handler that gets fired AFTER webforms and do another write to the database. Which isn't this one of the powers of the hooks? To modify so we have less db writes/reads?

The code I am using to bypass this until the above patch of #1 gets committed is:

<?php
/**
 * Additional submit callback for form webform_component_edit_form.
 */
function mymodule_form_webform_email_edit_form_submit(&$form, &$form_state) {

  if(!empty($form_state['values']['myfield'])) {
    $eid = $form_state['values']['eid'];
    $email = array(
      'eid' => $eid,
      'nid' => $form['#node']->nid,
      'extra' => empty($form['#node']->webform['emails'][$eid]['extra']) ? FALSE : $form['#node']->webform['emails'][$eid]['extra'],
    );

    foreach ($form_state['values']['myfield'] as $item => $value) {
      $email['extra'][$item] = $value;
    }

    $email['extra'] = empty($email['extra']) ? '' : serialize($email['extra']);
    $success = drupal_write_record('webform_emails', $email, array('nid', 'eid'));
  }
}
?>

Notice that I am doing an additional write AND having to create a little bit of processing code just to get this in unscathed.

So please commit the above patch +1+1 it has very little effect and makes the email form work similar to the rest of webform's edit forms.

Status: Needs review » Needs work

The last submitted patch, webform_emails-extra-config.patch, failed testing.

dobe’s picture

StatusFileSize
new600 bytes

Reroll

dobe’s picture

Status: Needs work » Needs review
pbosmans’s picture

@dobe
Thx for updating the patch.
I needed it on another site, with succes.
Hopefully it will be committed.

chris matthews’s picture

Version: 7.x-4.10 » 7.x-4.x-dev

The 3 year old patch in #7 still applies cleanly to the latest 7.x-4.x-dev and would be a nice feature to have.

Checking patch includes/webform.emails.inc...
Hunk #1 succeeded at 554 (offset 9 lines).
Applied patch includes/webform.emails.inc cleanly.
liam morland’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.