gmap_cck_widget($op, &$node, $field, &$items)
gmap_addons/gmap_cck.module, line 376
Define the behavior of a widget.
$op What kind of action is being performed. Possible values:
$field The field the action is being performed on.
&$items The contents of the field in this node. Changes to this variable will be saved back to the node object.
This varies depending on the operation.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
<?php
function gmap_cck_widget($op, &$node, $field, &$items) {
switch ($op) {
case 'prepare form values':
// db-value (serialized array) is in $items[0]['value'];
$items[0]['raw'] = unserialize($items[0]['value']);
// show some gpx-data?
if (!empty($field['gpx'])) {
_gmap_cck_check_gpx_source($items[0]['raw'], $field, $node);
}
// if ($field['multiple']) { ??? }
break;
case 'form':
$rd =& $items[0]['raw']; // raw data
if (empty($rd)) $rd = array();
$ndefs = array(
'maptype' => $field['maptype'],
'width' => $field['width'],
'height' => $field['height'],
'zoom' => $field['zoom'],
'latlong' => $field['latlong'],
);
if (isset($rd['gpx'])) {
$gpx_support = array('#value' => 'GPX support enabled');
_gmap_cck_get_gpx($rd, $field, $node);
}
$ndefs = array_merge(gmap_defaults(), $ndefs, $rd);
$hide = array('mapid' => 1, // type=hidden
'width' => 1, 'height' => 1, 'alignment' => 1, // 'zoom' => 2,
'maptype' => 1, 'controltype' => 1, 'macro' => 2,
);
$form = gmap_macro_builder_form($ndefs, $hide);
// remove/hide unwanted parts of form
$mf =& $form['macroform'];
$mf['#title'] = t('Select map view');
unset($mf['overlayedit'], $mf['address']);
foreach ($mf as $key => $val) {
if ($key[0] == '#') continue;
$mf['#tree'] = true;
$mf['#parents'] = array($field['field_name']);
}
$form[$field['field_name']] = $form['macroform'];
unset($form['macroform']);
if (isset($gpx_support)) {
$form['gpx_support'] = $gpx_support;
}
return $form;
case 'process form values':
// TODO: if ($field['multiple']) ...
// get the values and build serialized array for db-save
/* $ms = '[gmap zoom='. $items['zoom'] .'|center='.
$items['latlong'] .'|width='. $field['width'] .'|height='.
$field['height'] .'|id=gmap_'. $field['field_name'] .'|control='.
$field['controltype'] .'|type='. $field['maptype'] .']';
*/
$v = array('zoom' => $items['zoom'], 'latlong' => $items['latlong']);
// TODO: add more props like 'markers', gpx-file, ...
foreach ($items as $delta => $item) {
unset($items[$delta]);
}
// show some gpx-data?
if (!empty($field['gpx'])) {
_gmap_cck_check_gpx_source($v, $field, $node);
}
$items[0]['value'] = serialize($v);// $ms;
break;
}
}
?>