Question: How can I import a Webform via the https://drupal.org/project/webform_share API?

What do I know/current state: The API shows a graphical UI to do it, but I'd need a way to do it via an exported function, if any (e.g. a function call like webform_share_import($formspec)).

Reason/scenario: Because I want to install some forms in the .install of a module.


Found: there's not an exported API, but an implementation of a regular form hook for the UI, which does all the magic (webform_share.module:123).

| improve this answer | |
  • It is disappointing to answer my own questions and find a negative one :(. – Luis Masuelli Mar 10 '14 at 22:50

See this issue.

In the comments, it shows that there is a function called _webform_share_eval() in the webform_share.module file.

function _webform_share_eval($str) {
  return empty($webform) ? FALSE : $webform;

It's very simple to use this to import a webform and save a node.

// Create the node
$node = new stdClass();
$node->type = 'webform';
$node->title = 'Contact Us';
$node->status = 1;

// Import the webform
$node->language = 'und';
$node->webform = _webform_share_eval(file_get_contents(drupal_get_path('module', 'mymodule') . '/webform.txt'));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.