public function SarniaViewsHandlerField::options_form in Sarnia 7
Build the handler configuration form.
Adds a Solr property select dropdown, and summons up a formatter settings form.
Overrides views_handler_field::options_form
See also
views_handler_field_field::options_form()
File
- handlers/
handler_field.inc, line 78
Class
- SarniaViewsHandlerField
- Field handler for displaying Solr fields in Views.
Code
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form_url = views_ui_build_form_url($form_state);
$form['solr_property'] = array(
'#type' => 'select',
'#title' => t('Solr property'),
'#options' => sarnia_index_get_field_options($this->definition['search_api_index']),
'#default_value' => $this->options['solr_property'],
'#ajax' => array(
'path' => $form_url,
),
'#submit' => array(
'views_ui_config_item_form_submit_temporary',
),
'#executes_submit_callback' => TRUE,
);
sarnia_element_add_combobox($form['solr_property']);
// Multivalue property settings
$server = search_api_server_load($this->sarnia_type_info['search_api_server']);
$solr_fields = $server
->getRemoteFields();
if (!empty($solr_fields[$this->options['solr_property']]) && $solr_fields[$this->options['solr_property']]
->isMultivalued()) {
$form['multivalue'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Multivalue property settings'),
);
$form['multivalue']['count'] = array(
'#type' => 'textfield',
'#title' => t('Number of values to display'),
'#description' => t('Maximum number of field values to display. Leave this at 0 to display all values.'),
'#default_value' => $this->options['multivalue']['count'],
'#element_validate' => array(
'views_element_validate_integer',
),
'#size' => 5,
);
$form['multivalue']['list_type'] = array(
'#type' => 'select',
'#title' => t('List type'),
'#options' => array(
'ul' => 'Unordered list',
'ol' => 'Ordered list',
'separator' => 'Separator',
),
'#default_value' => $this->options['multivalue']['list_type'],
);
$form['multivalue']['list_separator'] = array(
'#type' => 'textfield',
'#title' => t('Seperator'),
'#default_value' => $this->options['multivalue']['list_separator'],
'#states' => array(
'visible' => array(
'select[name="options[multivalue][list_type]"]' => array(
'value' => 'separator',
),
),
),
);
}
// Field formatter configuration, from
// views/modules/field/views_handler_field_field.inc
module_load_include('inc', 'views', 'modules/field/views_handler_field_field');
$field = field_info_field($this->definition['field_name']);
$formatters = array(
t('- None -'),
) + _field_view_formatter_options($field['type']);
$form['formatter'] = array(
'#type' => 'select',
'#title' => t('Formatter'),
'#options' => $formatters,
'#default_value' => $this->options['formatter'],
'#ajax' => array(
'path' => $form_url,
),
'#submit' => array(
'views_ui_config_item_form_submit_temporary',
),
'#executes_submit_callback' => TRUE,
);
// Get the currently selected formatter.
$format = $this->options['formatter'];
$formatter = field_info_formatter_types($format);
$settings = $this->options['settings'] + field_info_formatter_settings($format);
// Provide an instance array for hook_field_formatter_settings_form(). This
// mimics ctools_fields_fake_field_instance(), except it gets a real
// instance since we know our entity type.
$entity_type = $this->sarnia_type_info['machine_name'];
$instance = field_info_instance($entity_type, $this->definition['field_name'], $entity_type);
$instance['display']['_dummy'] = array(
'type' => $formatter,
'settings' => $settings,
);
// Store the settings in a '_dummy' view mode.
$instance['display']['_dummy'] = array(
'type' => $format,
'settings' => $settings,
);
// Get the settings form.
$settings_form = array(
'#value' => array(),
);
$function = (isset($formatter['module']) ? $formatter['module'] : '') . '_field_formatter_settings_form';
if (function_exists($function)) {
// views_handler_field_field.inc passes $form instead of array()
$settings_form = $function($field, $instance, '_dummy', array(), $form_state);
unset($settings_form['solr_property']);
}
$form['settings'] = $settings_form;
}