6 2. Hooks for registering selectors, properties and types.
8 4. Plugin class example.
9 5. sweaver_get_plugin().
14 10. General JS functions.
15 11. General CSS styles.
18 14. hook_sweaver_action().
20 ------------------------------------------------------
22 ------------------------------------------------------
25 * Implementation of hook_ctools_plugin_api().
27 function hook_ctools_plugin_api($owner, $api) {
28 if ($owner == 'sweaver' && $api == 'sweaver') {
29 return array('version' => 1);
33 ---------------------------------------------------------
34 2. Hooks for registering selectors, properties and types
35 ---------------------------------------------------------
38 * Implementation of hook_default_sweaver_selector().
40 function hook_default_sweaver_selector() {
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;
57 * Implementation of hook_default_sweaver_property().
59 function hook_default_sweaver_property() {
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',
84 $propertys['font-machine_name'] = $property;
86 // Yes you need to return propertys, that's the way Ctools works :)
91 * Implementation of hook_sweaver_type().
93 function sweaver_default_sweaver_type() {
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',
107 $types['machine_name'] = $type;
113 ---------------------------------------------------------
115 ---------------------------------------------------------
118 * Implementation of hook_sweaver_plugins().
120 function hook_sweaver_plugins() {
123 $plugins['yourpluginname'] = 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.
137 ---------------------------------------------------------
138 4. Plugin class example.
139 ---------------------------------------------------------
144 * All methods are optional.
146 class pluginname extends sweaver_plugin {
149 * Return module dependencies.
151 function sweaver_dependencies() {
152 return array('module');
158 function sweaver_menu(&$weight, $page_arguments, $base) {
159 // $page_arguments = array('plugin' => 'name_of_your_plugin');
161 // 'access arguments' => array('configure sweaver'),
162 // 'page callback' => 'sweaver_menu_callback',
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.
174 function sweaver_theme() {
175 // Return theming functions for Drupal.
181 function sweaver_init() {
182 // Do stuff during hook_init() of Drupal.
186 * Sweaver objects alter.
188 function sweaver_objects_alter(&$objects) {}
193 function sweaver_form() {
198 * Sweaver form render.
200 function sweaver_form_render(&$vars, &$form, $plugin) {
201 // Do some extra rendering on the form.
205 * Frontend css and js.
207 function sweaver_form_css_js(&$inline_settings) {
208 // Add css, js and manipulate the inline settings of sweaver.
212 * Frontend form submit.
214 function sweaver_form_submit($form, &$form_state) {
215 // Do something with the submitted values.
219 * Default menu callback.
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.
232 * Default sweaver menu callback validate.
234 function sweaver_menu_callback_validate($form, &$form_state) {
235 // Validate the submission.
239 * Default sweaver menu callback submit
241 function sweaver_menu_callback_submit($form, &$form_state) {
242 // Do something with the submitted values.
246 * Return false to not show editor.
248 public function show_editor() {
252 * Return true to allow access and false to deny.
254 public function sweaver_menu_access_callback($args) {
258 ------------------------------------------------------
259 5. sweaver_get_plugin().
260 ------------------------------------------------------
262 .You can use sweaver_get_plugin to get an object. This function will
263 load the plugin and return the class if found.
265 $object = sweaver_get_plugin('plugin_name');
266 $object->do_some_method();
268 ------------------------------------------------------
270 ------------------------------------------------------
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:
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';
284 ------------------------------------------------------
286 ------------------------------------------------------
288 sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return = 'string')
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.
294 ------------------------------------------------------
296 ------------------------------------------------------
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:
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'.
307 For inspiration, take a look at plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc.
309 ------------------------------------------------------
310 9. General functions.
311 ------------------------------------------------------
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.
318 ------------------------------------------------------
319 10. General JS functions.
320 ------------------------------------------------------
322 There are a couple of JS functions you can use in your plugins.
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.
334 - Drupal.Sweaver.hidePopup() {}
335 Closes the popup screen.
337 ------------------------------------------------------
338 11. General CSS styles.
339 ------------------------------------------------------
341 There are several css classes which you can use which will do all kinds of stuff
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
350 ------------------------------------------------------
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.
359 The variable in the database is 'sweaver_skin'.
361 ------------------------------------------------------
362 13. Theme extensions.
363 ------------------------------------------------------
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.
371 You can add a palette and 5 preview colors in your .info file, e.g.:
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
383 You can also define selectors per theme in the info file, eg:
385 sweaver[selectors][body] = Body
386 sweaver[selectors][h1] = Heading 1
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.
393 Those selectors will be exclusive. Which means that the
394 user will only be able to select and modify those defined selectors
396 To define inclusive selectors (which will be added to others
397 created in the regestry) you need to add options to your selectors
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
405 - The name must contain only lowercase letters, numbers, underscores or hyphens
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
415 Note: if you add new theme extensions but they don't show up,
416 then you need to clear the theme registry.
418 ------------------------------------------------------
419 14. hook_sweaver_action($action, $arguments).
420 ------------------------------------------------------
422 If you want other modules to act on certain actions happening in sweaver use
423 module_invoke_all('sweaver', 'action_name', $arguments);
425 Currently the Theme switch plugin is the first plugin calling this
426 so other modules can perform actions when switching theme.