ref #623692: Multiple File Upload - send as attachment

For the moment there's no way to send the attachment by email, since the code used to attach the file assumes a a $fid as parameter, which we don't have (we have an serialized array)

        if ($email['attachments']) {
          webform_component_include('file');
          foreach ($node->webform['components'] as $component) {
            if (webform_component_feature($component['type'], 'attachment') && !empty($submission->data[$component['cid']]['value'][0])) {
              $file = webform_get_file($submission->data[$component['cid']]['value'][0]); // <== Doesn't work
              if ($file) {
                $attachments[] = $file;
              }
            }
          }
        }
<

I'll try to fix it

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Status: Active » Needs work

This looks pretty good, but if we're going to be adding a hook (or Webform's version of a hook), we should make the file component implement it too instead of special-casing the built-in component. Then it makes for an example that other modules could reference. Unless we have other purposes, calling the hook "attachments" might be a suitable name (so file.inc would have _webform_attachments_file()). We also need documentation of the new hook in webform_hooks.php.

Jelle_S’s picture

Title: 'hook' _webform_get_files_component » 'hook' _webform_attachments_component
Status: Needs work » Needs review
FileSize
2.98 KB
2.82 KB

Two patches attached, one for 6.x and one for 7.x

Jelle_S’s picture

Forgot to edit a part of the comments in webform_hooks.php after copy-pasting them

Jelle_S’s picture

Fixed some minor mistakes in the documentation

quicksketch’s picture

Status: Needs review » Needs work

Looks pretty good buy you're missing the implementation of the new hook in components/file.inc.

Jelle_S’s picture

+++ b/components/file.incundefined
@@ -656,3 +656,12 @@ function webform_get_file($fid) {
+
+/**
+ * Implements _webform_attachments_component().
+ */
+function _webform_attachments_file($component, $value) {
+  $file = (array)webform_get_file($value[0]);
+  $files = array($file);
+  return $files;

here it is... It just reuses the existing function webform_get_file :-)

Jelle_S’s picture

Status: Needs work » Needs review
quicksketch’s picture

Title: 'hook' _webform_attachments_component » Add new webform callback to allow custom components to attach multiple files
Status: Needs review » Fixed

Thanks Jelle_S, you're quite right. I finally got a chance to review this patch in earnest today and it works great. Committed to both 3.x branches. Extra props for the D6 backport.

Status: Fixed » Closed (fixed)

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