You are here

function mvf_handler_filter_mvf::set_default_options in Measured Value Field 7

Set default options.

For backward compatibility, it sends the options array; this is a feature that will likely disappear at some point.

Overrides views_object::set_default_options

File

views/mvf_handler_filter_mvf.inc, line 22

Class

mvf_handler_filter_mvf
Base Views Filter Handler for field types defined in MVF module.

Code

function set_default_options() {
  parent::set_default_options();

  // We load field API definition array of the MVF field on which current
  // instance of the filter operates.
  $this->options['field_definition'] = field_info_field($this->definition['field_name']);

  // Inserting "whatever" default units, now that we have MVF field on hands,
  // we can do it.
  $entityreference = mvf_field_mockup($this->options['field_definition'], 'unit');
  $entity_type = $entityreference['settings']['target_type'];
  $efq = new EntityFieldQuery();
  $efq
    ->entityCondition('entity_type', $entity_type);
  $efq
    ->entityCondition('bundle', reset($entityreference['settings']['handler_settings']['target_bundles']));
  $efq
    ->range(0, 1);
  $result = $efq
    ->execute();
  $default_unit_id = array_keys($result[$entity_type]);
  $default_unit_id = reset($default_unit_id);
  foreach ($this->options['value'] as $k => $v) {
    $this->options['value'][$k][mvf_subfield_to_column('unit')] = $default_unit_id;
  }
}