2
// $Id: content_handler_field.inc,v 1.1.2.14 2009/03/18 19:20:52 yched Exp $
6
* The subclass adds basic field and formatter info,
7
* for field-specific subclasses to use if they need to.
9
* Fields could extend this class if they want field and formatter handling
10
* but don't want the multiple value grouping options created by
11
* content_handler_field_multiple.
13
class content_handler_field extends views_handler_field_node {
16
function construct() {
18
$this->content_field = content_fields($this->definition['content_field_name']);
21
function init(&$view, $options) {
22
$field = $this->content_field;
23
parent::init($view, $options);
24
if ($field['multiple']) {
25
$this->additional_fields['delta'] = 'delta';
27
// Make sure we grab enough information to build a pseudo-node with enough
28
// credentials at render-time.
29
$this->additional_fields['type'] = array('table' => 'node', 'field' => 'type');
30
$this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid');
31
$this->additional_fields['vid'] = array('table' => 'node', 'field' => 'vid');
34
function options(&$options) {
35
parent::options($options);
36
$field = $this->content_field;
38
// Override views_handler_field_node's default label
39
$options['label'] = '';
40
$options['label_type'] = 'widget';
41
$options['format'] = 'default';
45
* Provide formatter option.
47
function options_form(&$form, &$form_state) {
48
parent::options_form($form, $form_state);
49
// TODO: do we want the 'link to node' checkbox ?
50
// That's usually formatters business...
52
$field = $this->content_field;
53
$options = $this->options;
55
$form['label_type'] = array(
56
'#title' => t('Label'),
60
'widget' => t('Widget label (@label)', array('@label' => $field['widget']['label'])),
61
'custom' => t('Custom'),
63
'#default_value' => $options['label_type'],
66
$form['label'] = array(
67
'#title' => t('Custom label'),
68
'#type' => 'textfield',
69
'#default_value' => $options['label'],
70
'#process' => array('views_process_dependency'),
71
'#dependency' => array('radio:options[label_type]' => array('custom')),
75
$field_types = _content_field_types();
76
$formatters = array();
77
if (is_array($field_types[$field['type']]['formatters'])) {
78
foreach ($field_types[$field['type']]['formatters'] as $name => $info) {
79
$formatters[$name] = $info['label'];
82
$form['format'] = array(
83
'#title' => t('Format'),
85
'#options' => $formatters,
87
'#default_value' => $options['format'],
94
* Make sure some value is stored as a label.
96
* Don't use t(), since Views' views_handler_field already has
97
* $this->options['label'] marked as a translatable field.
99
* @see http://drupal.org/node/285470
101
function options_submit($form, &$form_state) {
102
switch ($form_state['values']['options']['label_type']) {
104
$form_state['values']['options']['label'] = '';
107
$form_state['values']['options']['label'] = $this->content_field['widget']['label'];
114
* Now that we save the label in the submit process above we could
115
* get rid of this function. Leave it here for now to be sure the
116
* label works for fields that haven't been updated since this
117
* change was made, since $this->options['label'] will be missing a
118
* value until it is updated in the view.
120
* Don't use t(), since Views' views_handler_field already has
121
* $this->options['label'] marked as a translatable field.
124
$field = $this->content_field;
125
switch ($this->options['label_type']) {
129
return $field['widget']['label'];
131
return $this->options['label'];
136
* Return DIV or SPAN based upon the field's element type.
138
function element_type() {
139
if (isset($this->definition['element type'])) {
140
return $this->definition['element type'];
142
// TODO Figure out exactly when to return a div or a <span>. Any field
143
// that ever needs to be shown inline in Views UI. It needs to return
144
// a div for textareas to prevent wrapping a <span> around a <p>.
145
// Earl says we need to be sure that other fields we don't know
146
// about won't end up wrapping a span around a block-level element.
147
if ($this->content_field['widget']['type'] == 'text_textarea') {
155
function options_validate($form, &$form_state) { }
158
* Provide text for the administrative summary
160
function admin_summary() {
161
// Display the formatter name.
162
$field = $this->content_field;
163
$field_types = _content_field_types();
164
if (isset($field_types[$field['type']]['formatters'][$this->options['format']])) {
165
return t($field_types[$field['type']]['formatters'][$this->options['format']]['label']);
169
function render($values) {
170
$field = $this->content_field;
171
$options = $this->options;
172
$db_info = content_database_info($field);
174
// Build a pseudo-node from the retrieved values.
175
$node = drupal_clone($values);
176
$node->type = $values->{$this->aliases['type']};
177
$node->nid = $values->{$this->aliases['nid']};
178
$node->vid = $values->{$this->aliases['vid']};
179
// Some formatters need to behave differently depending on the build_mode
180
// (for instance: preview), so we provide one.
181
$node->build_mode = NODE_BUILD_NORMAL;
184
foreach ($db_info['columns'] as $column => $attributes) {
185
$item[$column] = $values->{$this->aliases[$attributes['column']]};
188
$item['#delta'] = $field['multiple'] ? $values->{$this->aliases['delta']} : 0;
190
return $this->render_link(content_format($field, $item, $options['format'], $node), $values);
b'\\ No newline at end of file'