views_handler_field_node_link.inc

  1. 3.x modules/node/views_handler_field_node_link.inc
  2. 2.x modules/node/views_handler_field_node_link.inc

Definition of views_handler_field_node_link.

File

modules/node/views_handler_field_node_link.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_node_link.
  5. */
  6. /**
  7. * Field handler to present a link to the node.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_node_link extends views_handler_field_entity {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['text'] = array('default' => '', 'translatable' => TRUE);
  15. return $options;
  16. }
  17. function options_form(&$form, &$form_state) {
  18. $form['text'] = array(
  19. '#type' => 'textfield',
  20. '#title' => t('Text to display'),
  21. '#default_value' => $this->options['text'],
  22. );
  23. parent::options_form($form, $form_state);
  24. // The path is set by render_link function so don't allow to set it.
  25. $form['alter']['path'] = array('#access' => FALSE);
  26. $form['alter']['external'] = array('#access' => FALSE);
  27. }
  28. function render($values) {
  29. if ($entity = $this->get_value($values)) {
  30. return $this->render_link($entity, $values);
  31. }
  32. }
  33. function render_link($node, $values) {
  34. if (node_access('view', $node)) {
  35. $this->options['alter']['make_link'] = TRUE;
  36. $this->options['alter']['path'] = "node/$node->nid";
  37. $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
  38. return $text;
  39. }
  40. }
  41. }