/[drupal]/contributions/modules/views/handlers/views_handler_field_boolean.inc
ViewVC logotype

Contents of /contributions/modules/views/handlers/views_handler_field_boolean.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Jun 25 21:49:17 2009 UTC (5 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
#488818 by overall: Fix typo in boolean filter documentation.
1 <?php
2 // $Id: views_handler_field_boolean.inc,v 1.2 2009/01/30 00:01:41 merlinofchaos Exp $
3
4 /**
5 * A handler to provide proper displays for booleans.
6 *
7 * Allows for display of true/false, yes/no, on/off.
8 *
9 * @ingroup views_field_handlers
10 */
11 class views_handler_field_boolean extends views_handler_field {
12 function option_definition() {
13 $options = parent::option_definition();
14
15 $options['type'] = array('default' => 'yes-no');
16 $options['not'] = array('definition bool' => 'reverse');
17
18 return $options;
19 }
20
21 function options_form(&$form, &$form_state) {
22 parent::options_form($form, $form_state);
23 $form['type'] = array(
24 '#type' => 'select',
25 '#title' => t('Output format'),
26 '#options' => array(
27 'yes-no' => t('Yes/No'),
28 'true-false' => t('True/False'),
29 'on-off' => t('On/Off'),
30 ),
31 '#default_value' => $this->options['type'],
32 );
33 $form['not'] = array(
34 '#type' => 'checkbox',
35 '#title' => t('Reverse'),
36 '#description' => t('If checked, true will be displayed as false.'),
37 '#default_value' => $this->options['not'],
38 );
39 }
40
41 function render($values) {
42 $value = $values->{$this->field_alias};
43 if (!empty($this->options['not'])) {
44 $value = !$value;
45 }
46
47 switch ($this->options['type']) {
48 case 'yes-no':
49 default:
50 return $value ? t('Yes') : t('No');
51 case 'true-false':
52 return $value ? t('True') : t('False');
53 case 'on-off':
54 return $value ? t('On') : t('Off');
55 }
56 }
57 }

  ViewVC Help
Powered by ViewVC 1.1.2