function finder_optionwidgets_finder_element in Finder 7
Same name and namespace in other branches
- 6 modules/finder_optionwidgets/finder_optionwidgets.module \finder_optionwidgets_finder_element()
Implements hook_finder_element().
See also
hook_finder_element()
File
- modules/
finder_optionwidgets/ finder_optionwidgets.module, line 147 - The finder optionwidgets module.
Code
function finder_optionwidgets_finder_element($element, &$form_element) {
$finder = finder_load($element->finder_id);
$fields =& $element->settings['choices']['field'];
foreach ($fields as $key => $field) {
$field_info[$key] = finder_split_field($field);
$field_names[$key] = $field_info[$key]['field'];
}
if ($element->element == 'select') {
$form_element['#type'] = 'select';
$properties = array(
'multiple',
'size',
);
if (isset($element->settings['form']['multiple']) && $element->settings['form']['multiple']) {
if (!is_array($form_element['#default_value'])) {
$form_element['#default_value'] = explode("\n", $form_element['#default_value']);
}
}
}
elseif ($element->element == 'buttons') {
if ($element->settings['form']['multiple']) {
$form_element['#type'] = 'checkboxes';
if (!is_array($form_element['#default_value'])) {
$form_element['#default_value'] = explode("\n", $form_element['#default_value']);
}
}
else {
$form_element['#type'] = 'radios';
}
}
elseif ($element->element == 'onoff') {
$form_element['#type'] = 'checkbox';
$properties = array(
'return_value',
);
}
if (isset($properties)) {
foreach ((array) $properties as $property) {
if (isset($element->settings['form'][$property])) {
$form_element['#' . $property] = $element->settings['form'][$property];
}
}
}
$options = finder_find($finder, array(
$element->finder_element_id => NULL,
), 'choices');
$form_element['#options'] = array();
foreach ((array) $options as $key => $option) {
$display = theme('finder_optionwidgets_' . $element->element . '_option', array(
'option' => $option,
'element' => $element,
));
$value = theme('finder_optionwidgets_' . $element->element . '_value', array(
'option' => $option,
'element' => $element,
));
if ($display && $value) {
if (!empty($element->settings['choices']['rewrite']['php'])) {
$variables = array(
'finder_element' => $element,
'value' => $display,
'key' => $value,
'option' => $option,
);
$display = finder_eval($element->settings['choices']['rewrite']['php'], $variables);
}
$form_element['#options'][$value] = $display;
}
}
if (isset($element->settings['form']['empty'])) {
$empty = array(
'' => $element->settings['form']['empty_text'],
);
if ($element->settings['form']['empty'] == 'prepend') {
$form_element['#options'] = $empty + $form_element['#options'];
}
elseif ($element->settings['form']['empty'] == 'append') {
$form_element['#options'] = $form_element['#options'] + $empty;
}
}
}