webform_handler_field_node_link_edit.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Views handler to display an edit link for Webform configuration.
  4. *
  5. * Field handler to present a link node edit.
  6. */
  7. class webform_handler_field_node_link_edit extends views_handler_field_node_link {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function option_definition() {
  12. $options = parent::option_definition();
  13. $options['subpath'] = array('default' => '');
  14. return $options;
  15. }
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form['subpath'] = array(
  22. '#type' => 'textfield',
  23. '#title' => t('Subpath'),
  24. '#default_value' => $this->options['subpath'],
  25. '#field_prefix' => 'node/NID/webform/',
  26. );
  27. }
  28. /**
  29. * Renders the link.
  30. */
  31. public function render_link($node, $values) {
  32. // Ensure node is webform-enabled and user has access to edit this node.
  33. if (!in_array($node->type, webform_node_types()) || !node_access('update', $node)) {
  34. return;
  35. }
  36. $this->options['alter']['make_link'] = TRUE;
  37. $this->options['alter']['path'] = "node/$node->nid/webform" .
  38. (strlen($this->options['subpath']) ? '/' . $this->options['subpath'] : '');
  39. $text = !empty($this->options['text']) ? $this->options['text'] : t('edit webform');
  40. return $text;
  41. }
  42. }