| 20 |
); |
); |
| 21 |
// list of themes |
// list of themes |
| 22 |
$themes = array( |
$themes = array( |
|
'drawing_canvas', |
|
|
'drawing_group', |
|
|
'drawing_file', |
|
|
'drawing_ellipse', |
|
|
'drawing_rectangle', |
|
|
'drawing_line', |
|
|
'drawing_polyline', |
|
|
'drawing_polygon', |
|
|
'drawing_path', |
|
|
'drawing_text', |
|
|
'drawing_circle', |
|
| 23 |
'drawing', |
'drawing', |
| 24 |
); |
); |
| 25 |
|
// modules can easily add to this list by implementing hook_drawing_theme_alter(). |
| 26 |
|
// modules requiring advanced manipulation should use hook_theme_registry_alter(). |
| 27 |
|
drupal_alter('drawing_theme', $themes); |
| 28 |
foreach ($themes as $theme) { |
foreach ($themes as $theme) { |
| 29 |
$drawing_themes[$theme] = $drawing; |
$drawing_themes[$theme] = $drawing; |
| 30 |
} |
} |
| 54 |
$form = array(); |
$form = array(); |
| 55 |
$form['drawing_type'] = array( |
$form['drawing_type'] = array( |
| 56 |
'#type' => 'radios', |
'#type' => 'radios', |
| 57 |
'#title' => t('Set toolkit'), |
'#title' => t('Default toolkit'), |
| 58 |
'#default_value' => variable_get('drawing_type', 'drawing_svg'), |
'#default_value' => variable_get('drawing_type', 'drawing_svg'), |
| 59 |
'#description' => t('Select which toolkit you want to enable on the site.'), |
'#description' => t('Select the default toolkit to use on the site.'), |
| 60 |
'#options' => drawing_get_all_methods(), |
'#options' => drawing_get_all_methods(), |
| 61 |
); |
); |
| 62 |
return system_settings_form($form); |
return system_settings_form($form); |
| 133 |
* The themed output as rendered by drupal_render(). |
* The themed output as rendered by drupal_render(). |
| 134 |
*/ |
*/ |
| 135 |
function drawing_render_canvas($canvas_id, &$canvas) { |
function drawing_render_canvas($canvas_id, &$canvas) { |
| 136 |
|
$canvas['#pre_render'][] = 'drawing_pre_render_canvas'; |
| 137 |
// Don't override #theme if someone already set it. |
// Don't override #theme if someone already set it. |
| 138 |
if (!isset($canvas['#theme'])) { |
if (!isset($canvas['#theme'])) { |
| 139 |
init_theme(); |
init_theme(); |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
/** |
/** |
| 150 |
|
* Recursively pre render the canvas elements. |
| 151 |
|
* |
| 152 |
|
* @param $canvas |
| 153 |
|
* The canvas to process |
| 154 |
|
* @param $attributes |
| 155 |
|
* An array of attributes to pass down. |
| 156 |
|
* @return |
| 157 |
|
* The updated canvas. |
| 158 |
|
*/ |
| 159 |
|
function drawing_pre_render_canvas($canvas) { |
| 160 |
|
if (!isset($canvas['#method'])) { |
| 161 |
|
$canvas['#method'] = drawing_get_method($canvas); |
| 162 |
|
} |
| 163 |
|
if ($canvas['#type']) { |
| 164 |
|
$canvas['#type'] = 'drawing_'. $canvas['#type']; |
| 165 |
|
$canvas['#handler'] = $canvas['#method'] .'_'. $canvas['#type']; |
| 166 |
|
} |
| 167 |
|
foreach (element_children($canvas) as $child) { |
| 168 |
|
// pass down the #method |
| 169 |
|
$canvas[$child]['#method'] = $canvas['#method']; |
| 170 |
|
$canvas[$child] = drawing_pre_render_canvas($canvas[$child]); |
| 171 |
|
} |
| 172 |
|
// allow toolkit modules to add to this pre_render |
| 173 |
|
if (function_exists($canvas['#handler'])) { |
| 174 |
|
$canvas = $canvas['#handler']($canvas); |
| 175 |
|
} |
| 176 |
|
return $canvas; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
/** |
| 180 |
* Prepares a structured canvas array by adding required elements, |
* Prepares a structured canvas array by adding required elements, |
| 181 |
* and executing any hook_drawing_canvas_alter functions. |
* and executing any hook_drawing_canvas_alter functions. |
| 182 |
* |
* |
| 187 |
* An associative array containing the structure of the canvas. |
* An associative array containing the structure of the canvas. |
| 188 |
*/ |
*/ |
| 189 |
function drawing_prepare_canvas($canvas_id, &$canvas) { |
function drawing_prepare_canvas($canvas_id, &$canvas) { |
|
if ($canvas['#type'] == 'drawing_canvas') { |
|
|
$canvas += _element_info('drawing_canvas'); |
|
|
} |
|
|
elseif ($canvas['#type'] == 'drawing_file') { |
|
|
$canvas += _element_info('drawing_file'); |
|
|
} |
|
| 190 |
foreach (module_implements('drawing_canvas_alter') as $module) { |
foreach (module_implements('drawing_canvas_alter') as $module) { |
| 191 |
$function = $module .'_drawing_canvas_alter'; |
$function = $module .'_drawing_canvas_alter'; |
| 192 |
$function($form_id, $form); |
$function($canvas_id, $canvas); |
| 193 |
} |
} |
| 194 |
return $canvas; |
return $canvas; |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
/** |
/** |
| 198 |
* Extract the defined method, defaults to 'drawing_svg'. |
* Extract the defined method, defaults to 'drawing_svg'. |
| 199 |
|
* Method can be explicitly set on the element, or the default config will be used. |
| 200 |
*/ |
*/ |
| 201 |
function drawing_get_method() { |
function drawing_get_method($element = NULL) { |
| 202 |
static $drawing_method; |
$drawing_method = $element['#method'] ? 'drawing_'. $element['#method'] : variable_get('drawing_method', 'drawing_svg'); |
|
if (empty($drawing_method)) { |
|
|
$drawing_method = variable_get('drawing_method', 'drawing_svg'); |
|
|
} |
|
| 203 |
return $drawing_method; |
return $drawing_method; |
| 204 |
} |
} |
| 205 |
|
|
| 218 |
} |
} |
| 219 |
|
|
| 220 |
/** |
/** |
|
* Implementation of hook_elements(). |
|
|
*/ |
|
|
function drawing_elements() { |
|
|
$method = variable_get('drawing_method', 'drawing_svg'); |
|
|
$type['drawing_canvas'] = array( |
|
|
'#width' => '200px', |
|
|
'#height' => '200px', |
|
|
); |
|
|
$type['drawing_group'] = array( |
|
|
'#width' => '200px', |
|
|
'#height' => '200px', |
|
|
); |
|
|
$type['drawing_file'] = array( |
|
|
'#height' => '200px', |
|
|
'#width' => '200px', |
|
|
); |
|
|
return $type; |
|
|
} |
|
|
|
|
|
/** |
|
| 221 |
* Theme function. |
* Theme function. |
| 222 |
*/ |
*/ |
| 223 |
function theme_drawing($element) { |
function theme_drawing($element) { |
|
$method = drawing_get_method(); |
|
|
return theme($method .'_'. $element['#type'], $element); |
|
|
} |
|
|
|
|
|
/* |
|
|
To do: |
|
|
|
|
|
chx says we should use '#process to tell the element that it's parent is svg. |
|
|
quote: "add a #process to the element and propagate down the value. |
|
|
for now I'm just applying svg |
|
|
|
|
|
Another idea; use preprocess functions in hook_theme to deal with the 'method'? |
|
|
|
|
|
*/ |
|
| 224 |
|
return theme($element['#handler'], $element); |
| 225 |
|
} |