-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec_mapeditor.misc.inc
114 lines (102 loc) · 3.13 KB
/
ec_mapeditor.misc.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* @file
* Contains code with function names that do not comply with standards.
*
* Functions in this file could not be renamed at the moment of quality
* assurance review without breaking the module. They cannot be renamed because
* Drupal expects specific naming when dealing with entities. As discussed in
* https://webgate.ec.europa.eu/fpfis/wikis/x/AjjCBw .
*/
/**
* Constructs the map form.
*/
function map_form($form, &$form_state, $map) {
$form_state['map'] = $map;
// Provides a title field.
$form['title'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => t('Name'),
'#default_value' => $map->title,
);
// Provides a description field.
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $map->description,
);
// Stores the user ID.
$form['uid'] = array(
'#type' => 'value',
'#value' => $map->uid,
);
// Provides a field to store various map settings.
$settings = new EcMapeditorMapSettings();
if (!empty($map->settings)) {
$settings->customize(drupal_json_decode($map->settings));
}
// @todo. how to prevent this?
$settings = $settings->settings;
// Provides a checkbox to show /hide Disclaimer.
$form['show_disclaimer'] = array(
'#type' => 'checkbox',
'#title' => t('Show Disclaimer'),
'#default_value' => $settings['show_disclaimer'],
'#weight' => 96,
);
// Provides a checkbox to show /hide Author.
$form['show_author'] = array(
'#type' => 'checkbox',
'#title' => t('Show Author'),
'#default_value' => $settings['show_author'],
'#weight' => 97,
);
// Provides a checkbox to show /hide settings field.
$form['show_settings'] = array(
'#type' => 'checkbox',
'#title' => t('Show settings'),
'#default_value' => $settings['show_settings'],
'#weight' => 98,
);
$form['settings'] = array(
'#weight' => 99,
'#title' => t('Settings'),
'#type' => 'textarea',
'#default_value' => isset($map->settings) ? $map->settings : '',
'#description' => t('Settings (json encoded)'),
'#states' => array(
'visible' => array(
':input[name="show_settings"]' => array('checked' => TRUE),
),
),
);
// Adds field UI fields.
field_attach_form('map', $map, $form, $form_state);
// Adds common map form elements.
$elements = array('height', 'center', 'zoom', 'tiles');
$custom_form_elements = _ec_mapeditor_custom_map_form_elements($elements, $settings);
$form += $custom_form_elements;
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions'] = array(
'#weight' => 100,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save map'),
'#submit' => $submit + array('ec_mapeditor_form_submit'),
);
// Adds delete button when editing a map.
$map_id = entity_id('map', $map);
if (!empty($map_id) && ec_mapeditor_access('edit', $map)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('ec_mapeditor_form_submit_delete'),
);
}
return $form;
}