function farm_fields_handler_filter_entity::value_form in farmOS 7
Options form subform for setting options.
This should be overridden by all child classes and it must define $form['value'].
Overrides views_handler_filter_many_to_one::value_form
See also
options_form()
File
- modules/
farm/ farm_fields/ views/ handlers/ farm_fields_handler_filter_entity.inc, line 36 - Definition of farm_fields_handler_filter_entity.
Class
- farm_fields_handler_filter_entity
- Provide an exposed filter that entity reference options in a select list.
Code
function value_form(&$form, &$form_state) {
$options = array();
// Get the entity IDs.
$ids = $this
->entity_ids();
// Load the entities and create a list of select options.
$entities = entity_load($this->entity_type, $ids);
foreach ($entities as $entity) {
list($id, $vid, $bundle) = entity_extract_ids($this->entity_type, $entity);
$options[$id] = entity_label($this->entity_type, $entity);
}
// Set the default value.
$default_value = (array) $this->value;
if (!empty($form_state['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (!empty($this->options['expose']['reduce'])) {
$options = $this
->reduce_value_options($options);
if (!empty($this->options['expose']['multiple']) && empty($this->options['expose']['required'])) {
$default_value = array();
}
}
if (empty($this->options['expose']['multiple'])) {
if (empty($this->options['expose']['required']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
$default_value = 'All';
}
elseif (empty($default_value)) {
$keys = array_keys($options);
$default_value = array_shift($keys);
}
elseif ($default_value == array(
'',
)) {
$default_value = 'All';
}
else {
$copy = $default_value;
$default_value = array_shift($copy);
}
}
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Select entities'),
'#multiple' => TRUE,
'#options' => $options,
'#size' => min(9, count($options)),
'#default_value' => $default_value,
);
if (!empty($form_state['exposed']) && isset($identifier) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $default_value;
}
if (empty($form_state['exposed'])) {
// Retain the helper option
$this->helper
->options_form($form, $form_state);
// Show help text if not exposed to end users.
$form['value']['#description'] = t('Leave blank for all. Otherwise, the first selection will be the default instead of "Any".');
}
}