function getlocations_leaflet_field_widget_form in Get Locations 7
Same name and namespace in other branches
- 7.2 modules/getlocations_leaflet/getlocations_leaflet.module \getlocations_leaflet_field_widget_form()
Implements hook_field_widget_form(). Return the form for a single field widget.
Parameters
$form: The form structure where widgets are being attached to. This might be a full form structure, or a sub-element of a larger form.
$form_state: An associative array containing the current state of the form.
$field: The field structure.
$instance: The field instance.
$langcode: The language associated with $items.
$items: Array of default values for this field.
$delta: The order of this item in the array of subelements (0, 1, 2, etc).
$element: A form element array containing basic properties for the widget.
Return value
The form elements for a single widget for this field.
File
- modules/
getlocations_leaflet/ getlocations_leaflet.module, line 1094 - getlocations_leaflet.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_leaflet_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
switch ($instance['widget']['type']) {
case 'getlocations_leaflet_map':
// is this real or a demo in settings
$active = TRUE;
if (empty($element['#entity'])) {
$active = FALSE;
}
$entity_type = $element['#entity_type'];
$bundle = $element['#bundle'];
$module = getlocations_get_current_supported_module();
$fieldnames = array();
$query = db_select('field_config', 'f');
$query
->fields('i', array(
'field_name',
'data',
));
$query
->join('field_config_instance', 'i', 'f.id=i.field_id');
$query
->condition('i.bundle', $bundle)
->condition('f.module', $module)
->condition('i.entity_type', $entity_type)
->condition('f.active', 1);
$rows = $query
->execute();
foreach ($rows as $row) {
$data = unserialize($row->data);
$fieldnames[$row->field_name] = $data['label'];
}
$cardinality = $field['cardinality'];
// Wrap in a fieldset for single fields
if ($cardinality == 1) {
$element['#type'] = 'fieldset';
$element['#collapsible'] = TRUE;
$element['#collapsed'] = FALSE;
}
if (!empty($fieldnames)) {
$element['#delta'] = $delta;
$dval = isset($items[$delta]['locative_field_name']) ? $items[$delta]['locative_field_name'] : (isset($instance['default_value'][$delta]['locative_field_name']) ? $instance['default_value'][$delta]['locative_field_name'] : '');
if ($active && module_exists('views_bulk_operations') && isset($settings['input_text']) && $settings['input_text']) {
$element['locative_field_name'] = array(
'#type' => 'textfield',
'#title' => t('Location Field'),
'#description' => t('Field to take locative data from'),
'#default_value' => $dval,
'#size' => 30,
);
}
else {
// items only see which field, no choice
if ($active && $dval) {
$element['locative_field_name'] = array(
'#type' => 'value',
'#value' => $dval,
);
$element['locative_field_name_markup'] = array(
'#markup' => '<p>' . t('Locative data taken from !f', array(
'!f' => $fieldnames[$dval],
)) . '</p>',
);
}
else {
$element['locative_field_name'] = array(
'#type' => 'select',
'#title' => t('Location Field'),
'#options' => $fieldnames,
'#description' => t('Field to take locative data from'),
'#default_value' => $dval,
);
}
}
}
else {
if (!$active) {
$element['some_info'] = array(
'#type' => 'markup',
'#markup' => '<p>' . t('You must attach an instance of !m', array(
'!m' => $module,
)),
);
}
}
break;
}
return $element;
}