utility-form.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @file Utility form, conversion and rendering functions for image processes
  4. */
  5. /**
  6. * Prepare a subform for displaying positioning fields
  7. *
  8. * Helper function to render a common element.
  9. */
  10. function imagecache_actions_pos_form($action) {
  11. $defaults = array(
  12. 'xpos' => 'center',
  13. 'ypos' => 'center',
  14. );
  15. $action = array_merge($defaults, (array) $action);
  16. $form = array(
  17. #'#theme' => 'canvasactions_pos_form',
  18. 'xpos' => array(
  19. '#type' => 'textfield',
  20. '#title' => t('X offset'),
  21. '#default_value' => $action['xpos'],
  22. '#size' => 6,
  23. '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'),
  24. '#element_validate' => array('imagecache_actions_validate_number'),
  25. ),
  26. 'ypos' => array(
  27. '#type' => 'textfield',
  28. '#title' => t('Y offset'),
  29. '#default_value' => $action['ypos'],
  30. '#size' => 6,
  31. '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'),
  32. '#element_validate' => array('imagecache_actions_validate_number'),
  33. ),
  34. );
  35. return $form;
  36. }
  37. /**
  38. * Ensure the numbers are valid.
  39. *
  40. * Set blanks to zero, just so the status summary doesn't get odd blanks
  41. */
  42. function imagecache_actions_validate_number(&$element, &$form_state) {
  43. if (empty($element['#value'])) {
  44. form_set_value($element, 0, $form_state);
  45. }
  46. }
  47. /**
  48. * @todo Please document this function.
  49. * @see http://drupal.org/node/1354
  50. */
  51. function imagecache_actions_validate_alpha(&$element, &$form_status) {
  52. if (!is_numeric($element['#value']) || $element['#value'] < 1 || $element['#value'] > 100) {
  53. form_set_error(join('][', $element['#parents']), t('Opacity must be a number between 1 and 100.'));
  54. }
  55. }