Projet

Général

Profil

Paste
Télécharger (13,1 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / sweaver / API.txt @ a5572547

1

    
2
Table of contents
3
------------------
4

    
5
1. Hook for cTools.
6
2. Hooks for registering selectors, properties and types.
7
3. Plugins hook.
8
4. Plugin class example.
9
5. sweaver_get_plugin().
10
6. Images handler.
11
7. Session handling
12
8. Sweaver popups.
13
9. General functions.
14
10. General JS functions.
15
11. General CSS styles.
16
12. Skins
17
13. Theme extensions.
18
14. hook_sweaver_action().
19

    
20
------------------------------------------------------
21
1. Hook for cTools
22
------------------------------------------------------
23

    
24
/**
25
 * Implementation of hook_ctools_plugin_api().
26
 */
27
function hook_ctools_plugin_api($owner, $api) {
28
  if ($owner == 'sweaver' && $api == 'sweaver') {
29
    return array('version' => 1);
30
  }
31
}
32

    
33
---------------------------------------------------------
34
2. Hooks for registering selectors, properties and types
35
---------------------------------------------------------
36

    
37
/**
38
 * Implementation of hook_default_sweaver_selector().
39
 */
40
function hook_default_sweaver_selector() {
41

    
42
  $selectors = array();
43

    
44
  $selector = new stdClass;
45
  $selector->api_version = 1;
46
  $selector->disabled = FALSE; // Set this to true if you want to disable this by default.
47
  $selector->name = 'machine_name';
48
  $selector->description = 'Description';
49
  $selector->selector_selector = '.selector'; // css selector.
50
  $selector->selector_highlight = FALSE; // Whether to highlight the selector in the active path. 
51
  $selectors['machine_name'] = $selector;
52
  
53
  return $selectors;
54
}
55

    
56
/**
57
 * Implementation of hook_default_sweaver_property().
58
 */
59
function hook_default_sweaver_property() {
60

    
61
  $propertys = array();
62

    
63
  // Font.
64
  $property = new stdClass;
65
  $property->api_version = 1;
66
  $property->disabled = FALSE; // Set this to true if you want to disable this by default.
67
  $property->name = 'machine_name';
68
  $property->description = 'Description';
69
  $property->property = '';  // The actual css property. Seperate multiple values by spaces.
70
  $property->property_parent = ''; // Wether this property has a parent.
71
  $property->property_type = 'select'; // Can be select, slider, image, color or parent.
72
  // Prefix or suffix: eg: padding has suffix 'px', url has prefix 'url(' and suffix ');'
73
  $property->property_prefix = '';
74
  $property->property_suffix = '';
75
  // Slider min & max - only applicable for slider.
76
  $property->property_slider_min = ''; // Minimum for slider  , usually 1.
77
  $property->property_slider_max = ''; // Maximum for slider
78
  // Options are only applicable for select.
79
  $property->property_options = array(
80
        'option_1' => 'Readable option 1',
81
        'option_2' => 'Readable option 2',
82
        'option_2' => 'Readable option 3',
83
      );
84
  $propertys['font-machine_name'] = $property;
85

    
86
  // Yes you need to return propertys, that's the way Ctools works :)
87
  return $propertys;
88
}
89

    
90
/**
91
 * Implementation of hook_sweaver_type().
92
 */
93
function sweaver_default_sweaver_type() {
94

    
95
  $types = array();
96

    
97
  $type = new stdClass;
98
  $type->api_version = 1;
99
  $type->disabled = FALSE;
100
  $type->name = 'machine_name';
101
  $type->description = 'Description';
102
  $type->type_options = array(
103
    'property_1' => 'property_1',
104
    'property_2' => 'property_2',
105
    'property_3' => 'property_2',
106
  );
107
  $types['machine_name'] = $type;
108
  
109
  return $types;
110
}
111

    
112

    
113
---------------------------------------------------------
114
3. Plugins hook.
115
---------------------------------------------------------
116

    
117
/**
118
 * Implementation of hook_sweaver_plugins().
119
 */
120
function hook_sweaver_plugins() {
121
  $plugins = array();
122
  
123
  $plugins['yourpluginname'] = array(
124
    'handler' => array(
125
      'tab' => t('Tab name'), // If you want to do something in the frontend.
126
      'tab_description' => t('Description of your plugin in frontend'),
127
      'path' => drupal_get_path('module', 'yourmodulename') .'/plugins/yourpluginname',
128
      'file' => 'yourpluginname.inc',
129
      'class' => 'yourclassnameusuallythesameasyourpluginname',
130
      'parent' => 'sweaver_plugin', // This is required.
131
    ),
132
  );
133
  
134
  return $plugins;
135
}
136

    
137
---------------------------------------------------------
138
4. Plugin class example.
139
---------------------------------------------------------
140

    
141
/**
142
 * Your plugin
143
 *
144
 * All methods are optional.
145
 */
146
class pluginname extends sweaver_plugin {
147

    
148
  /**
149
   * Return module dependencies.
150
   */
151
  function sweaver_dependencies() {
152
    return array('module');
153
  }
154

    
155
  /**
156
   * Menu registry.
157
   */
158
  function sweaver_menu(&$weight, $page_arguments, $base) {
159
    // $page_arguments = array('plugin' => 'name_of_your_plugin'); 
160
    //  $base = array(
161
    //    'access arguments' => array('configure sweaver'),
162
    //    'page callback' => 'sweaver_menu_callback',
163
    //  );
164
    // You can use these to add to your menu items.
165
    // Other stuff you can return in page arguments:
166
    // callback_method: defaults to sweaver_menu_callback - optional.
167
    // return_method : default to drupal_get_form - optional
168
    // Return menu items for Drupal.
169
  }
170

    
171
  /**
172
   * Theme registry.
173
   */
174
  function sweaver_theme() {
175
    // Return theming functions for Drupal.
176
  }
177

    
178
  /**
179
   * Init function.
180
   */
181
  function sweaver_init() {
182
    // Do stuff during hook_init() of Drupal.
183
  }
184

    
185
  /**
186
   * Sweaver objects alter.
187
   */
188
  function sweaver_objects_alter(&$objects) {}
189

    
190
  /**
191
   * Sweaver form.
192
   */
193
  function sweaver_form() {
194
    return array();
195
  }
196

    
197
  /**
198
   * Sweaver form render.
199
   */
200
  function sweaver_form_render(&$vars, &$form, $plugin) {
201
    // Do some extra rendering on the form.
202
  }
203

    
204
  /**
205
   * Frontend css and js.
206
   */
207
  function sweaver_form_css_js(&$inline_settings) {
208
    // Add css, js and manipulate the inline settings of sweaver.
209
  }
210

    
211
  /**
212
   * Frontend form submit.
213
   */
214
  function sweaver_form_submit($form, &$form_state) {
215
    // Do something with the submitted values.
216
  }
217
  
218
  /**
219
   * Default menu callback.
220
   */
221
  function sweaver_menu_callback() {
222
    // Return a form or simply some other output.
223
    // Must return a form array() by default. This
224
    // is the default method you need to implement.
225
    // This makes is possible to have menu callbacks in your
226
    // class without having to create a new file.
227
    // All plugins - except for editor.admin.inc' use this
228
    // technique. See sweaver_menu_callback() for options.
229
  }
230

    
231
  /**
232
   * Default sweaver menu callback validate.
233
   */
234
  function sweaver_menu_callback_validate($form, &$form_state) {
235
    // Validate the submission.
236
  }
237

    
238
  /**
239
   * Default sweaver menu callback submit
240
   */
241
  function sweaver_menu_callback_submit($form, &$form_state) {
242
    // Do something with the submitted values.
243
  }
244
  
245
  /**
246
   * Return false to not show editor.
247
   */
248
  public function show_editor() {
249
  }
250

    
251
  /**
252
   * Return true to allow access and false to deny.
253
   */
254
  public function sweaver_menu_access_callback($args) {
255
  }  
256
}
257

    
258
------------------------------------------------------
259
5. sweaver_get_plugin().
260
------------------------------------------------------
261

    
262
.You can use sweaver_get_plugin to get an object. This function will
263
load the plugin and return the class if found.
264

    
265
$object = sweaver_get_plugin('plugin_name');
266
$object->do_some_method();
267

    
268
------------------------------------------------------
269
6. Images handler.
270
------------------------------------------------------
271

    
272
The editor searches for a class which implements a method called sweaver_images_handler.
273
By default, the images plugin which comes in the sweaver module provides extra images.
274
You can change this by setting the variable 'sweaver_plugin_handle_images' to the name
275
of the plugin you want. The plugin itself must implement following method:
276

    
277
myclass extends sweaver_plugin {
278
  function sweaver_images_handler(&$images) {
279
    $images['file_path_1'] = 'Real name 1'; 
280
    $images['file_path_2'] = 'Real name 2'; 
281
  }
282
}
283

    
284
------------------------------------------------------
285
7. Session handling
286
------------------------------------------------------
287

    
288
sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return = 'string')
289

    
290
Set or return session variables which you can easily use througout the plugin system.
291
Much easier than using $_SESSION variables. This function does it all for you.
292
Use it as much as you can.
293

    
294
------------------------------------------------------
295
8. Sweaver popups.
296
------------------------------------------------------
297

    
298
You can put forms in a sweaver popup, which we do for example in the themesettings plugin.
299
Following things in the sweaver_form method will make sure this happens:
300

    
301
    $form['#popups'] = array(); // Initialize the popups array.
302
    $form['#popups'][] = $key; // Put a FAPI key in the popups array.
303
    // Link class: popup-link This will trigger the popup.
304
    // The link needs an id with at least 'link' in the name. The form
305
    // it has to show needs the same id, but with 'link' replaced as 'data'.
306
    
307
For inspiration, take a look at plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc.
308

    
309
------------------------------------------------------
310
9. General functions.
311
------------------------------------------------------
312

    
313
- sweaver_get_current_style($reset = FALSE) {}
314
  Returns the css for the theme.
315
- sweaver_get_theme_info($theme) {}
316
  Returns the theme info for the theme.
317

    
318
------------------------------------------------------
319
10. General JS functions.
320
------------------------------------------------------
321

    
322
There are a couple of JS functions you can use in your plugins.
323

    
324
- Drupal.Sweaver.invokes.processCSS()
325
  Must a return CSS definitions to write for the editor.
326
  Implemented in editor and custom css plugin. 
327
- Drupal.Sweaver.switchTab(remove_tab, show_tab) {}
328
  Switch to a tab in the editor
329
- Drupal.Sweaver.setMessage(messages) {}
330
  Sets a message above the editor. Times out after 5 seconds.
331
- Drupal.Sweaver.showPopup(message) {}
332
  Shows a popup screen with any content you like. 
333
  Gets a close button.
334
- Drupal.Sweaver.hidePopup() {}
335
  Closes the popup screen.
336

    
337
------------------------------------------------------
338
11. General CSS styles.
339
------------------------------------------------------
340

    
341
There are several css classes which you can use which will do all kinds of stuff
342

    
343
- popup-link: put this on a link and this will trigger a sweaver popup
344
- sweaver-switch-to-style: adds a brush icon
345
- container: lets a div float
346
- container-1 to container-4: determines the width (from 25% to 100%)
347
- float-left: floats to left
348
- form-floater: makes form items and submits float
349

    
350
------------------------------------------------------
351
12. Skins.
352
------------------------------------------------------
353
You can create new skins for the editor if you like. Simply
354
create a new directory with your name and copy the files which
355
are found in default, rename them to the name of your new skin
356
and adjust them to your likings. On the general configuration screen, 
357
you can select the skin you like.
358

    
359
The variable in the database is 'sweaver_skin'.
360

    
361
------------------------------------------------------
362
13. Theme extensions.
363
------------------------------------------------------
364

    
365
1. Palettes
366

    
367
Every theme can define color palettes. These palettes are
368
extra css files that can be added to your theme and that
369
overwrite the default css.
370

    
371
You can add a palette and 5 preview colors in your .info file, e.g.:
372

    
373
sweaver[palettes][pink][name] = Pink
374
sweaver[palettes][pink][file] = palettes/pink.css
375
sweaver[palettes][pink][colors][] = #f98cf0
376
sweaver[palettes][pink][colors][] = #af63a9
377
sweaver[palettes][pink][colors][] = #af63a9
378
sweaver[palettes][pink][colors][] = #cbb2c9
379
sweaver[palettes][pink][colors][] = #cbb2c9 
380

    
381
2. Selectors
382

    
383
You can also define selectors per theme in the info file, eg:
384

    
385
sweaver[selectors][body] = Body
386
sweaver[selectors][h1] = Heading 1
387
...
388

    
389
The order is how you define it in the info file.
390
In the backend you can select if these selectors
391
are to be used instead of those in the database.
392

    
393
Those selectors will be exclusive. Which means that the
394
user will only be able to select and modify those defined selectors
395

    
396
To define inclusive selectors (which will be added to others 
397
created in the regestry) you need to add options to your selectors
398

    
399
sweaver[selectors][h4][name] = h4
400
sweaver[selectors][h4][description] = Heading 4
401
sweaver[selectors][h4][selector_highlight] = TRUE
402
sweaver[selectors][h4][weight] = 20
403
sweaver[selectors][h4][type] = add
404

    
405
 - The name must contain only lowercase letters, numbers, underscores or hyphens
406
 and must be unique.
407
 - The selector description is the text shown to the Sweaver front end user
408
 - The selector_highlight property define weither or not the selector should be
409
 highlighted by default
410
 - The weight is a very important element as it define the priority of this
411
 selector on others. A value between 20 and 50 is advisable for major selectors
412
 and a value between 70 and 100 for minors ones.
413
 - The type is either set as add for inclusive or replace f r excluse selector
414

    
415
Note: if you add new theme extensions but they don't show up,
416
then you need to clear the theme registry.
417

    
418
------------------------------------------------------
419
14. hook_sweaver_action($action, $arguments).
420
------------------------------------------------------
421

    
422
If you want other modules to act on certain actions happening in sweaver use
423
module_invoke_all('sweaver', 'action_name', $arguments);
424

    
425
Currently the Theme switch plugin is the first plugin calling this
426
so other modules can perform actions when switching theme.