Skip to content

Instantly share code, notes, and snippets.

@Cyberschorsch
Created March 28, 2013 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cyberschorsch/5264059 to your computer and use it in GitHub Desktop.
Save Cyberschorsch/5264059 to your computer and use it in GitHub Desktop.
Complete Option Form
<?php
/**
* Define the options form to enable selection of flags.
*/
function options_form(&$form, &$form_state) {
// Load all flags and types of each flag.
$flags = flag_get_flags('taxonomy_term');
// Combine all types (=vocabs) into one option array.
$flag_types = array();
$flag_options = array();
foreach ($flags as $flagname => $value) {
// $flag_types is the array storing all vocabs.
$flag_types = array_merge($flag_types, $value->types);
// $flag_options is the array storing all possible Flags.
$flag_options[$flagname] = $flagname;
}
$form['flags'] = array(
'#type' => 'checkboxes',
'#title' => t('Choose the Flags'),
'#options' => $flag_options,
'#process' => array('form_process_checkboxes'),
'#default_value' => $this->options['flags'],
);
$form['vocabularies'] = array(
'#type' => 'checkboxes',
'#title' => t('Choose the Vocabularies'),
'#options' => drupal_map_assoc($flag_types),
'#process' => array('form_process_checkboxes'),
'#default_value' => $this->options['vocabularies'],
);
$form['fallback'] = array(
'#type' => 'textfield',
'#title' => t('Fallback value'),
'#description' => t('Value to use, when no item is flagged'),
'#default_value' => $this->options['fallback'],
);
$form['multiple_operator'] = array(
'#type' => 'select',
'#options' => array(
'+' => 'OR',
',' => 'AND',
),
'#title' => t('Operator for multiple values'),
'#default_value' => $this->options['multiple_operator'],
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment