views_handler_field_node_type.inc

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

File

modules/node/views_handler_field_node_type.inc
View source
  1. <?php
  2. /**
  3. * Field handler to translate a node type into its readable form.
  4. */
  5. class views_handler_field_node_type extends views_handler_field_node {
  6. function option_definition() {
  7. $options = parent::option_definition();
  8. $options['machine_name'] = array('default' => FALSE);
  9. return $options;
  10. }
  11. /**
  12. * Provide machine_name option for to node type display.
  13. */
  14. function options_form(&$form, &$form_state) {
  15. parent::options_form($form, $form_state);
  16. $form['machine_name'] = array(
  17. '#title' => t('Output machine name'),
  18. '#description' => t('Display field as the node type machine name.'),
  19. '#type' => 'checkbox',
  20. '#default_value' => !empty($this->options['machine_name']),
  21. );
  22. }
  23. /**
  24. * Render node type as human readable name, unless using machine_name option.
  25. */
  26. function render_name($data, $values) {
  27. if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
  28. return t(check_plain(node_get_types('name', $data)));
  29. }
  30. return check_plain($data);
  31. }
  32. function render($values) {
  33. return $this->render_link($this->render_name($values->{$this->field_alias}, $values), $values);
  34. }
  35. }