webform_handler_field_form_body.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Views handler to display the content of a webform form.
  4. *
  5. * Field handler to present the Webform form body to the user.
  6. */
  7. class webform_handler_field_form_body extends views_handler_field {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function construct() {
  12. parent::construct();
  13. $this->additional_fields['nid'] = 'nid';
  14. }
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function option_definition() {
  19. $options = parent::option_definition();
  20. $options['label'] = array('default' => 'Form', 'translatable' => TRUE);
  21. return $options;
  22. }
  23. /**
  24. *
  25. */
  26. public function query() {
  27. $this->ensure_my_table();
  28. $this->add_additional_fields();
  29. }
  30. /**
  31. *
  32. */
  33. public function render($values) {
  34. $node = node_load($values->{$this->aliases['nid']});
  35. if (node_access('view', $node)) {
  36. // Populate $node->content['webform'] by reference.
  37. webform_node_view($node, 'form');
  38. $form_body = isset($node->content['webform']) ? drupal_render($node->content['webform']) : NULL;
  39. }
  40. else {
  41. return;
  42. }
  43. return $form_body;
  44. }
  45. }