data_taxonomy_views_handler_field_form.inc in Data 6
File
data_taxonomy/views/data_taxonomy_views_handler_field_form.inc
View source
<?php
class data_taxonomy_views_handler_field_form extends views_handler_field {
protected $id;
function option_definition() {
$options = parent::option_definition();
$options['vocabularies'] = array(
'default' => array(),
);
$options['path'] = array(
'default' => '',
);
return $options;
}
function options_form(&$form, &$form_state) {
$options = array();
$table = data_get_table($this->table);
$meta = $table
->get('meta');
if (!empty($meta['data_taxonomy']['vocabularies'])) {
foreach ($meta['data_taxonomy']['vocabularies'] as $vid) {
$options[$vid] = data_taxonomy_get_vocabulary($vid)->name;
}
}
if (!empty($options)) {
$form['vocabularies'] = array(
'#title' => t('Enabled vocabularies'),
'#description' => t('Display a tagging form for each of the selected vocabularies. Only vocabularies that are enabled for this table are available. Edit this table\'s definition in admin/build/data to enable vocabularies.'),
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $this->options['vocabularies'],
);
}
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Term path'),
'#default_value' => $this->options['path'],
'#description' => t('Path to link terms with. Use "%" to represent arguments of the current view, use !tid to designate where the term id should be placed, use !term to designate where the term name should be placed. For example "data/%/!tid/%"'),
);
}
function query() {
$this
->ensure_my_table();
$table = data_get_table($this->table);
$meta = $table
->get('meta');
if (!empty($meta['data_taxonomy']['vocabularies']) && isset($meta['data_taxonomy']['id'])) {
$this->id = $this->query
->add_field($this->table_alias, $meta['data_taxonomy']['id']);
}
$this
->add_additional_fields();
}
function render($values) {
$output = '';
$table = data_get_table($this->table);
$meta = $table
->get('meta');
if (!empty($meta['data_taxonomy']['vocabularies'])) {
foreach ($meta['data_taxonomy']['vocabularies'] as $vid) {
if (!empty($this->options['vocabularies'][$vid])) {
$vocabulary = data_taxonomy_get_vocabulary($vid);
$output .= drupal_get_form('data_taxonomy_tagging_form', $vocabulary->vid, $values->{$this->id}, $this->table, $this->options['path'], is_array($this->view->args) ? $this->view->args : array());
}
}
}
return $output;
}
function label() {
return '';
}
}