How do you programmatically create a webform with a managed_file type? I haven't been able to find a single example of how to create a webform with a managed_file type.

The webform initially had the type 'file', but needs to be changed to accept multiple attachments. When the type is changed to 'managed_file', the field for uploading attachments does not render.

Here is my code snippet for the attachment field:

7 =&gt; array(
    'name' =&gt; t('Attachment'),
    'form_key' =&gt; 'attachment',
    'type' =&gt; 'managed_file',
    'upload_location' =&gt; NULL,
    'pid' =&gt; 1,
    'weight' =&gt; 6,
    'value' =&gt; '',
    'required' =&gt; '0',
    'extra' =&gt; array(
      'directory' =&gt; 'story',
      'title_display' =&gt; 'before',
      'private' =&gt; 0,
      'wrapper_classes' =&gt; '',
      'css_classes' =&gt; '',
      'filtering' =&gt; array(
        'size' =&gt; '2 MB',
        'types' =&gt; array(
          'gif',
          'jpg',
          'jpeg',
          'png',
          'txt',
          'rtf',
          'html',
          'pdf',
          'doc',
          'docx',
          'ppt',
          'pptx',
          'xls',
          'xlsx',
          'zip',
        ),
        'addextensions' =&gt; '',
      ),
      'rename' =&gt; '',
      'scheme' =&gt; 'public',
      'progress_indicator' =&gt; 'throbber',
      'description' =&gt; '',
      'attributes' =&gt; array(),
      'analysis' =&gt; FALSE,
    ),
  ),
);


Thanks much!
Making a couple of leaps here:


I couldn't find a D8 release for Webform so assuming D7
I'm assuming by managed_file (which is a FAPI element type) you mean a field API file field, as you mentioned making it accept multiple files (which the managed_file element doesn't have any support for).


So with those in mind...

Webform implements its own set of components, of which file is one type; it doesn't use the field API, so unfortunately you can't attach field API fields of any type to it.

The out-of-the-box file component doesn't support multiple uploads, but there's a contributed module, Webform Multiple File, which does:


  Module Webform Multiple File provides new Webform component for multiple file uploading. The module based on principles of file field widget and has similar design.