You are here

function global_filter_create_field_instance_widget in Views Global Filter 7

Same name and namespace in other branches
  1. 8 global_filter.widgets.inc \global_filter_create_field_instance_widget()

Cast widget in the mould of the widget configured for the supplied's field.

Parameters

string $option_all_text: Currently not used. See global_filter_options_none().

object $field: the field

array $instance: the instance

array $form: the form

array $form_state: the form state

1 call to global_filter_create_field_instance_widget()
global_filter_create_widget in ./global_filter.widgets.inc
Based on the requested or field-implied widget.

File

./global_filter.widgets.inc, line 267
global_filter.widgets.inc

Code

function global_filter_create_field_instance_widget($option_all_text, $field, $instance, &$form, &$form_state) {
  if (!isset($form['#parents'])) {

    // Must be set for most widgets before creation.
    $form['#parents'] = array();
  }

  // Add some context to the widget. This allows us for instance to make sure
  // that the Date widget doesn't impose its defaults.
  $instance['widget']['is_global_filter'] = TRUE;

  // $items is used to set the default value on the widget.
  if ($instance['widget']['module'] == 'date') {
    $items = global_filter_set_instance_date_widget_value($field, $instance, $form_state);
  }
  else {

    // Any widget other than the Date widgets.
    $session_value = global_filter_get_session_value($field['field_name']);
    $items = global_filter_set_instance_widget_value($session_value, $field, $form_state);
  }

  // Uncomment next two lines to obtain control over the option list, with the
  // exception of the first 'none' option. See global_filter_options_list().
  // $field['real_module'] = $field['module'];
  // $field['module'] = 'global_filter';
  // Trying to add/suppress 'All' option. The statement below doesn't have the
  // desired effect.
  // $instance['required'] = ($option_all_text == '<none>');
  $lang = $form_state['language'];

  // Note last argument, $delta=0, in this call. We don't want multiple
  // occurrences of a widget, except for Date, which is handled above.
  $form += field_default_form($instance['entity_type'], NULL, $field, $instance, $lang, $items, $form, $form_state, 0);
}