You are here

class data_taxonomy_views_handler_field_form in Data 6

Provide a form to associate data records with taxonomy terms.

Hierarchy

Expanded class hierarchy of data_taxonomy_views_handler_field_form

1 string reference to 'data_taxonomy_views_handler_field_form'
data_taxonomy_views_data in data_taxonomy/views/data_taxonomy.views.inc
Implementation of hook_views_data().

File

data_taxonomy/views/data_taxonomy_views_handler_field_form.inc, line 6

View source
class data_taxonomy_views_handler_field_form extends views_handler_field {
  protected $id;

  /**
   * Describe provided options and default values.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['vocabularies'] = array(
      'default' => array(),
    );
    $options['path'] = array(
      'default' => '',
    );
    return $options;
  }

  /**
   * Suppress other options and provide a selection of vocabularies for which
   * tagging forms will be displayed.
   */
  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/%"'),
    );
  }

  /**
   * Add field on which we join.
   */
  function query() {
    $this
      ->ensure_my_table();

    // Add the id field for this table to the query.
    $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();
  }

  /**
   * Render form.
   */
  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;
  }

  /**
   * Omit label output.
   */
  function label() {
    return '';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
data_taxonomy_views_handler_field_form::$id protected property
data_taxonomy_views_handler_field_form::label function Omit label output.
data_taxonomy_views_handler_field_form::options_form function Suppress other options and provide a selection of vocabularies for which tagging forms will be displayed.
data_taxonomy_views_handler_field_form::option_definition function Describe provided options and default values.
data_taxonomy_views_handler_field_form::query function Add field on which we join.
data_taxonomy_views_handler_field_form::render function Render form.