/[drupal]/contributions/modules/colorpicker/examples/colorpicker_example.module
ViewVC logotype

Diff of /contributions/modules/colorpicker/examples/colorpicker_example.module

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

revision 1.4, Sun Nov 4 04:54:49 2007 UTC revision 1.4.2.1, Mon Dec 1 01:09:33 2008 UTC
# Line 2  Line 2 
2    
3  // $Id$  // $Id$
4    
5    /**
6     * @file
7     * Example of a form that uses the colorpicker fields
8     */
9    
10  /*  /*
11   * Implementation of hook_menu().   * Implementation of hook_menu().
12   */   */
13  function colorpicker_example_menu($may_cache) {  function colorpicker_example_menu() {
14    $items = array();    $items['colorpicker/example'] = array(
15    if (!$may_cache) {      'title' => 'Color Picker Example',
16      $items[] = array(      'description' => 'An example of the color picker in use.',
17       'title' => t('Color Picker Example'),      'page callback' => 'colorpicker_example_callback',
18       'path' => 'colorpicker/example',      'access arguments' => user_access('access colorpicker example'),
19       'description' => t('An example of the color picker in use.'),      );
      'callback' => 'colorpicker_example_callback',  
      'access' => user_access('access colorpicker example') ,  
       );  
   }  
20    return $items;    return $items;
21  }  }
22    
# Line 30  function colorpicker_example_perm() { Line 31  function colorpicker_example_perm() {
31   * Callback for example color picker   * Callback for example color picker
32   */   */
33  function colorpicker_example_callback() {  function colorpicker_example_callback() {
34    $output = "<p>" . t('This is an example of a color picker in use.  Notice how some form elements are tied to one colorpicker, and others to another colorpicker.') . "</p>";    $output = '<p>'. t('This is an example of a color picker in use.  Notice how some form elements are tied to one colorpicker, and others to another colorpicker.') .'</p>';
35    $output .= drupal_get_form('colorpicker_example_callback_form');    $output .= drupal_get_form('colorpicker_example_callback_form');
36    return $output;    return $output;
37  }  }
# Line 40  function colorpicker_example_callback() Line 41  function colorpicker_example_callback()
41   */   */
42  function colorpicker_example_callback_form() {  function colorpicker_example_callback_form() {
43    $form = array();    $form = array();
44    
45    $form['colorpicker_example'] = array(    $form['colorpicker_example'] = array(
46      '#type' => 'colorpicker',      '#type' => 'colorpicker',
47      '#title' => t('Color picker'),      '#title' => t('Color picker'),
48      '#description' => t('This is the Farbtastic colorpicker.'),      '#description' => t('This is the Farbtastic colorpicker.'),
49    );    );
50    
51    $form['colorpicker_example_textfield'] = array(    $form['colorpicker_example_textfield'] = array(
52      '#type' => 'colorpicker_textfield',      '#type' => 'colorpicker_textfield',
53          '#title' => t('Color picker textfield'),      '#title' => t('Color picker textfield'),
54          '#description' => t('This is a textfield associated with the first Farbtastic color picker'),      '#description' => t('This is a textfield associated with the first Farbtastic color picker'),
55          '#default_value' => variable_get('colorpicker_example_textfield', '#ff33dd'),      '#default_value' => variable_get('colorpicker_example_textfield', '#ff33dd'),
56          '#colorpicker' => 'colorpicker_example',      '#colorpicker' => 'colorpicker_example',
57    );    );
58    
59    $form['colorpicker_example_textfield_2'] = array(    $form['colorpicker_example_textfield_2'] = array(
60      '#type' => 'colorpicker_textfield',      '#type' => 'colorpicker_textfield',
61          '#title' => t('Color picker textfield 2'),      '#title' => t('Color picker textfield 2'),
62          '#description' => t('This is another textfield associated with the first Farbtastic color picker'),      '#description' => t('This is another textfield associated with the first Farbtastic color picker'),
63          '#default_value' => variable_get('colorpicker_example_textfield', '#eedd55'),      '#default_value' => variable_get('colorpicker_example_textfield', '#eedd55'),
64          '#colorpicker' => 'colorpicker_example',      '#colorpicker' => 'colorpicker_example',
65    );    );
66    
67    $form['colorpicker_example_2'] = array(    $form['colorpicker_example_2'] = array(
68      '#type' => 'colorpicker',      '#type' => 'colorpicker',
69      '#title' => t('Color picker'),      '#title' => t('Color picker'),
70      '#description' => t('This is another Farbtastic colorpicker.'),      '#description' => t('This is another Farbtastic colorpicker.'),
71    );    );
72    
73    $form['colorpicker_example_textfield_3'] = array(    $form['colorpicker_example_textfield_3'] = array(
74      '#type' => 'colorpicker_textfield',      '#type' => 'colorpicker_textfield',
75          '#title' => t('Color picker textfield 3'),      '#title' => t('Color picker textfield 3'),
76          '#description' => t('This is a textfield associated with the second Farbtastic color picker'),      '#description' => t('This is a textfield associated with the second Farbtastic color picker'),
77          '#default_value' => variable_get('colorpicker_example_textfield', '#cccccc'),      '#default_value' => variable_get('colorpicker_example_textfield', '#cccccc'),
78          '#colorpicker' => 'colorpicker_example_2',      '#colorpicker' => 'colorpicker_example_2',
79    );    );
80    
81    $form['colorpicker_example_textfield_4'] = array(    $form['colorpicker_example_textfield_4'] = array(
82      '#type' => 'colorpicker_textfield',      '#type' => 'colorpicker_textfield',
83          '#title' => t('Color picker textfield 4'),      '#title' => t('Color picker textfield 4'),
84          '#description' => t('This is another textfield associated with the second Farbtastic color picker'),      '#description' => t('This is another textfield associated with the second Farbtastic color picker'),
85          '#default_value' => variable_get('colorpicker_example_textfield', '#000000'),      '#default_value' => variable_get('colorpicker_example_textfield', '#000000'),
86          '#colorpicker' => 'colorpicker_example_2',      '#colorpicker' => 'colorpicker_example_2',
87    );    );
88    
89    $form['submit'] = array(    $form['submit'] = array(
90      '#type' => 'submit',      '#type' => 'submit',
91      '#title' => t('Save'),      '#title' => t('Save'),
92      '#description' => t('Save the default values of this form'),      '#description' => t('Save the default values of this form'),
93      '#value' => t('Submit'),      '#value' => t('Save'),
94      '#submit' => TRUE      '#submit' => TRUE
95    );    );
96    
# Line 99  function colorpicker_example_callback_fo Line 100  function colorpicker_example_callback_fo
100  /*  /*
101   * Form builder function for custom colorpicker example callback   * Form builder function for custom colorpicker example callback
102   */   */
103  function colorpicker_example_callback_form_submit($form_id, $form_values) {  function colorpicker_example_callback_form_submit($form, &$form_state) {
104    variable_set('colorpicker_example_color', $form_values['colorpicker_example_color']);    variable_set('colorpicker_example_color', $form_state['values']['colorpicker_example_color']);
105    variable_set('colorpicker_example_textarea', $form_values['colorpicker_example_textarea']);    variable_set('colorpicker_example_textarea', $form_state['values']['colorpicker_example_textarea']);
106  }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.4.2.1

  ViewVC Help
Powered by ViewVC 1.1.2