/[drupal]/contributions/modules/gmap/gmap_macro_builder.module
ViewVC logotype

Contents of /contributions/modules/gmap/gmap_macro_builder.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Nov 24 17:49:55 2008 UTC (12 months ago) by bdragon
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, DRUPAL-6--1-1-RC1, HEAD
Changes since 1.5: +3 -3 lines
File MIME type: text/x-php
#338511, reported by goba: Rename "create macro" permission to "create gmap macro".
1 <?php
2 // $Id: gmap_macro_builder.module,v 1.5 2008/11/07 19:28:47 bdragon Exp $
3
4 /**
5 * @file
6 * GMap Macro Builder
7 *
8 * A dynamic interface to assist in the creation of gmap macro tags.
9 */
10
11 /**
12 * Implemenation of hook_help().
13 */
14 function gmap_macro_builder_help($path, $arg) {
15 switch ($path) {
16 case 'map/macro':
17 return t('You can use this interface to create a map macro suitable for pasting into a node or any other place that accepts a GMap macro.');
18 }
19 }
20
21 /**
22 * Implementation of hook_perm().
23 */
24 function gmap_macro_builder_perm() {
25 return array('create gmap macro');
26 }
27
28 /**
29 * Implementation of hook_menu().
30 */
31 function gmap_macro_builder_menu() {
32 $items['map/macro'] = array(
33 'type' => MENU_NORMAL_ITEM,
34 'title' => 'Build a GMap macro',
35 'access arguments' => array('create gmap macro'),
36 'page callback' => 'drupal_get_form',
37 'page arguments' => array('gmap_macro_builder_form'),
38 );
39 return $items;
40 }
41
42 /**
43 * Macro builder form.
44 * @param &$form_state
45 * The $form_state array.
46 * @param $settings
47 * Additional settings to apply to the macro map.
48 * @param $hide
49 * Fields to hide from the map. (See code for details.)
50 * Suggestions for better ways of doing this welcome!
51 */
52 function gmap_macro_builder_form(&$form_state, $settings = array(), $hide = array()) {
53 $form['macroform'] = array(
54 '#type' => 'fieldset',
55 '#title' => t('Gmap macro creation'),
56 '#theme' => 'gmap_macro',
57 );
58
59 $form['macroform']['mapdiv'] = array(
60 '#type' => 'gmap',
61 '#map' => 'macro_map',
62 '#settings' => array_merge(array(
63 'points' => array(),
64 'pointsOverlays' => array(),
65 'behavior' => array(
66 'dynmarkers' => TRUE,
67 ),
68 ), $settings),
69 );
70
71 $defaults = array_merge(gmap_defaults(), $settings);
72
73 $form['macroform']['overlayedit'] = array(
74 '#type' => 'gmap_overlay_edit',
75 '#map' => 'macro_map',
76 );
77 $form['macroform']['mapid'] = array(
78 '#type' => 'textfield',
79 '#title' => t('Map id attribute'),
80 '#description' => t('If you need to access this map from a script, you can assign a map ID here.'),
81 '#default_value' => '',
82 );
83 gmap_widget_setup($form['macroform']['mapid'], 'mapid', 'macro_map');
84
85 // @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui.
86 $baselayers = array();
87
88 foreach (module_implements('gmap') as $module) {
89 call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
90 }
91
92 $options = array();
93 foreach ($baselayers as $name => $layers) {
94 $options[$name] = array();
95 foreach ($layers as $k => $v) {
96 // @@@TODO: Only show the enabled ones?
97 $options[$name][$k] = $v['title'];
98 }
99 }
100
101 $form['macroform']['maptype'] = array(
102 '#type' => 'select',
103 '#title' => t('Map type'),
104 '#default_value' => $defaults['maptype'],
105 '#options' => $options,
106 );
107 gmap_widget_setup($form['macroform']['maptype'], 'maptype', 'macro_map');
108
109 // @@@TODO: We need to allow choosing an alternate set of baselayers...
110
111 $form['macroform']['controltype'] = array(
112 '#type' => 'select',
113 '#title' => t('Controls'),
114 '#options' => drupal_map_assoc(array('None', 'Small', 'Large')),
115 '#required' => FALSE,
116 '#default_value' => $defaults['controltype'],
117 );
118 gmap_widget_setup($form['macroform']['controltype'], 'controltype', 'macro_map');
119
120 $form['macroform']['address'] = array(
121 '#type' => 'gmap_address',
122 '#map' => 'macro_map',
123 '#title' => t('Address'),
124 '#default_value' => '',
125 );
126 $form['macroform']['latlong'] = array(
127 '#type' => 'gmap_latlon',
128 '#map' => 'macro_map',
129 '#title' => t('The Latitude and Longitude of the centre of the map'),
130 '#default_value' => $defaults['latlong'],
131 '#size' => 50,
132 );
133 $form['macroform']['width'] = array(
134 '#type' => 'textfield',
135 '#title' => t('Map width'),
136 '#default_value' => $defaults['width'],
137 '#size' => 25,
138 '#maxlength' => 25,
139 '#description' => t('The map width, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
140 );
141 gmap_widget_setup($form['macroform']['width'], 'width', 'macro_map');
142
143 $form['macroform']['height'] = array(
144 '#type' => 'textfield',
145 '#title' => t('Map height'),
146 '#default_value' => $defaults['height'],
147 '#size' => 25,
148 '#maxlength' => 25,
149 '#description' => t('The map height, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'),
150 );
151 gmap_widget_setup($form['macroform']['height'], 'height', 'macro_map');
152
153 $form['macroform']['alignment'] = array(
154 '#type' => 'gmap_align',
155 '#map' => 'macro_map',
156 '#title' => t('Alignment'),
157 );
158
159 $form['macroform']['zoom'] = array(
160 '#type' => 'select',
161 '#title' => t('The current magnification of the map'),
162 '#default_value' => $defaults['zoom'],
163 '#options' => drupal_map_assoc(range(0, 17)),
164 );
165 gmap_widget_setup($form['macroform']['zoom'], 'zoom', 'macro_map');
166
167 $form['macroform']['macro'] = array(
168 '#type' => 'gmap_macrotext',
169 '#map' => 'macro_map',
170 '#default_value' => '',
171 '#title' => t('Macro text'),
172 );
173
174 foreach ($hide as $field => $mode) {
175 if (isset($form['macroform'][$field])) {
176 if ($mode == 1) {
177 $form['macroform'][$field]['#type'] = 'hidden';
178 $form['macroform'][$field]['#value'] = $form['macroform'][$field]['#default_value'];
179 }
180 else if ($mode == 2) {
181 $form['macroform'][$field]['#prefix'] = '<div style="display: none;">';
182 $form['macroform'][$field]['#suffix'] = '</div>';
183 }
184 }
185 }
186
187 return $form;
188 }

  ViewVC Help
Powered by ViewVC 1.1.2