Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @file
  5. * Add captcha on the last page.
  6. */
  7.  
  8. /**
  9. * Set captcha on the last page in webform.
  10. */
  11. function custom_node_create_node_insert($node) {
  12. if ($node->type == 'product_review') {
  13. $body = field_get_items('node', $node, 'body');
  14. $comp = explode("\n", $body[0]['value']);
  15. $components = array();
  16. foreach ($comp as $c) {
  17. if ($c == '') {
  18. // Skip empty lines. Maybe the non-tech admin pressed an extra enter?
  19. continue;
  20. }
  21. // Create the webform components array. Not sure if we need all these
  22. // values, but let's be sure.
  23. $components = array(
  24. array(
  25. 'name' => 'body',
  26. 'form_key' => 'body',
  27. 'type' => 'markup',
  28. 'title' => t('Body'),
  29. 'value' => $node->body['und'][0]['value'],
  30. 'mandatory' => 1,
  31. 'weight' => 5,
  32. 'pid' => 0,
  33. 'extra' => array(
  34. 'title_display' => 'inline',
  35. 'private' => 0,
  36. ),
  37. ),
  38. array(
  39. 'name' => 'Product references',
  40. 'form_key' => 'product_references',
  41. 'type' => 'markup',
  42. 'title' => t('Product references'),
  43. 'value' => $node->field_product_references['und'][0]['nid'],
  44. 'mandatory' => 1,
  45. 'weight' => 6,
  46. 'pid' => 0,
  47. 'extra' => array(
  48. 'title_display' => 'inline',
  49. 'private' => 0,
  50. ),
  51. ),
  52. );
  53. }
  54.  
  55. // Alright, let's create the node object.
  56. $n = new stdClass();
  57. $n->type = 'webform';
  58. // Let the user be the author.
  59. $n->uid = $node->uid;
  60. // Let the 'order' title be the webform title.
  61. $n->title = $node->title;
  62. // I put them all on the frontpage.
  63. $n->promote = 1;
  64. // And we are allowed to comment.
  65. $n->comment = 2;
  66. $emails = array(
  67. array(
  68. 'email' => 'somebody@example.tld',
  69. 'subject' => 'default',
  70. 'from_name' => 'default',
  71. 'from_address' => 'default',
  72. 'template' => 'default',
  73. 'excluded_components' => array(),
  74. ),
  75. );
  76. // Enter webform array.
  77. $n->webform = array(
  78. 'confirmation' => '',
  79. 'confirmation_format' => NULL,
  80. 'redirect_url' => '<confirmation>',
  81. 'status' => '1',
  82. 'block' => '0',
  83. 'teaser' => '0',
  84. 'allow_draft' => '0',
  85. 'auto_save' => '0',
  86. 'record_exists' => TRUE,
  87. 'emails' => $emails,
  88. // Here comes our $components array.
  89. 'components' => $components,
  90. );
  91.  
  92.  
  93. // Save the node.
  94. node_save($n);
  95. // You could also put something like drupal_goto('node/' . $n->nid) here if
  96. // you want. My use case is different.
  97. }
  98. if ($node->type == 'webform') {
  99. $sids = db_select('webform_submissions', 'ws')
  100. ->fields('ws', array('sid'))
  101. ->execute()->fetchAll();
  102. foreach ($sids as $result) {
  103. $sid[] = $result->sid;
  104. }
  105. global $user;
  106. $sid_for_insert = end($sid) + 1;
  107. $id = db_insert('webform_submissions')
  108. ->fields(array('sid' => $sid_for_insert, 'nid' => $node->nid, 'serial' => $sid_for_insert, 'uid' => $user->uid, 'is_draft' => 0, 'submitted' => time()))
  109. ->execute();
  110. }
  111. //drupal_mail('custom_node_create', 1, 'somebody@example.tld', 'en', $params = array('$components'), $from = NULL, $send = TRUE);
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement