/[drupal]/contributions/modules/computed_field/computed_field.module
ViewVC logotype

Diff of /contributions/modules/computed_field/computed_field.module

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

revision 1.17.2.6, Tue May 19 00:44:17 2009 UTC revision 1.17.2.7, Fri Jul 31 23:26:18 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: computed_field.module,v 1.17.2.5 2009/05/18 23:49:00 moonshine Exp $  // $Id: computed_field.module,v 1.17.2.6 2009/05/19 00:44:17 moonshine Exp $
3    
4  /**  /**
5   * Implementation of cck hook_field_info()   * Implementation of cck hook_field_info()
# Line 32  function computed_field_field_settings($ Line 32  function computed_field_field_settings($
32          '#description' => t('The variables available to your code are: ') .'<code>&amp;$node, $field, and &amp;$node_field</code>'. t('. To set the value of the field, set ') .'<code>$node_field[0][\'value\']</code>'. t('. Here\'s a simple example which sets the computed field\'s value to the value of the sum of the number fields field_a and field_b: ') .'<code>$node_field[0][\'value\'] = $node->field_a[0][\'value\'] + $node->field_b[0][\'value\'];</code>',          '#description' => t('The variables available to your code are: ') .'<code>&amp;$node, $field, and &amp;$node_field</code>'. t('. To set the value of the field, set ') .'<code>$node_field[0][\'value\']</code>'. t('. Here\'s a simple example which sets the computed field\'s value to the value of the sum of the number fields field_a and field_b: ') .'<code>$node_field[0][\'value\'] = $node->field_a[0][\'value\'] + $node->field_b[0][\'value\'];</code>',
33          '#default_value' => !empty($field['code']) ? $field['code'] : '$node_field[0][\'value\'] = "";',          '#default_value' => !empty($field['code']) ? $field['code'] : '$node_field[0][\'value\'] = "";',
34        );        );
       $form['display'] = array(  
         '#type' => 'checkbox',  
         '#title' => t('Display this field'),  
         '#default_value' => is_numeric($field['code']) ? $field['code'] : TRUE ,  
       );  
35        $form['display_format'] = array(        $form['display_format'] = array(
36          '#type' => 'textarea',          '#type' => 'textarea',
37          '#title' => t('Display Format'),          '#title' => t('Display Format'),
# Line 91  function computed_field_field_settings($ Line 86  function computed_field_field_settings($
86        }        }
87        break;        break;
88      case 'save':      case 'save':
89        return array('code', 'display', 'display_format', 'store', 'data_type', 'data_length', 'data_not_NULL', 'data_default', 'data_sortable');        return array('code', 'display_format', 'store', 'data_type', 'data_length', 'data_not_NULL', 'data_default', 'data_sortable');
90      case 'database columns':      case 'database columns':
91        if ($field['store']) {        if ($field['store']) {
92          $columns = array('value' => array());          $columns = array('value' => array());
# Line 164  function computed_field_field($op, &$nod Line 159  function computed_field_field($op, &$nod
159        }        }
160        break;        break;
161      case 'view':      case 'view':
162        if ($field['display']) {        $items = array();
163          $items = array();        foreach ($node_field as $delta => $item) {
164          foreach ($node_field as $delta => $item) {          $items[$delta]['view'] = content_format($field, $item, 'default', $node);
           $items[$delta]['view'] = content_format($field, $item, 'default', $node);  
         }  
         return theme('field', $node, $field, $items, $teaser, $page);  
165        }        }
166          return theme('field', $node, $field, $items, $teaser, $page);
167        break;        break;
168      case 'validate':      case 'validate':
169        break;        break;
# Line 214  function computed_field_widget(&$form, & Line 207  function computed_field_widget(&$form, &
207   */   */
208  function computed_field_view_item($field, $node_field_item, $node = NULL) {  function computed_field_view_item($field, $node_field_item, $node = NULL) {
209    global $base_url;    global $base_url;
210    if ($field['display']) {  
211      $display = '';    $display = '';
212      eval($field['display_format']);    eval($field['display_format']);
213      return $display;    return $display;
   }  
214  }  }
215    
216  /**  /**

Legend:
Removed from v.1.17.2.6  
changed lines
  Added in v.1.17.2.7

  ViewVC Help
Powered by ViewVC 1.1.2