You are here

API.txt in Sweaver 6

Same filename and directory in other branches
  1. 7 API.txt
Table of contents
------------------

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

------------------------------------------------------
1. Hook for cTools
------------------------------------------------------

/**
 * Implementation of hook_ctools_plugin_api().
 */
function hook_ctools_plugin_api($owner, $api) {
  if ($owner == 'sweaver' && $api == 'sweaver') {
    return array('version' => 1);
  }
}

---------------------------------------------------------
2. Hooks for registering selectors, properties and types
---------------------------------------------------------

/**
 * Implementation of hook_default_sweaver_selector().
 */
function hook_default_sweaver_selector() {

  $selectors = array();

  $selector = new stdClass;
  $selector->api_version = 1;
  $selector->disabled = FALSE; // Set this to true if you want to disable this by default.
  $selector->name = 'machine_name';
  $selector->description = 'Description';
  $selector->selector_selector = '.selector'; // css selector.
  $selector->selector_highlight = FALSE; // Whether to highlight the selector in the active path. 
  $selectors['machine_name'] = $selector;
  
  return $selectors;
}

/**
 * Implementation of hook_default_sweaver_property().
 */
function hook_default_sweaver_property() {

  $propertys = array();

  // Font.
  $property = new stdClass;
  $property->api_version = 1;
  $property->disabled = FALSE; // Set this to true if you want to disable this by default.
  $property->name = 'machine_name';
  $property->description = 'Description';
  $property->property = '';  // The actual css property. Seperate multiple values by spaces.
  $property->property_parent = ''; // Wether this property has a parent.
  $property->property_type = 'select'; // Can be select, slider, image, color or parent.
  // Prefix or suffix: eg: padding has suffix 'px', url has prefix 'url(' and suffix ');'
  $property->property_prefix = '';
  $property->property_suffix = '';
  // Slider min & max - only applicable for slider.
  $property->property_slider_min = ''; // Minimum for slider  , usually 1.
  $property->property_slider_max = ''; // Maximum for slider
  // Options are only applicable for select.
  $property->property_options = array(
        'option_1' => 'Readable option 1',
        'option_2' => 'Readable option 2',
        'option_2' => 'Readable option 3',
      );
  $propertys['font-machine_name'] = $property;

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

/**
 * Implementation of hook_sweaver_type().
 */
function sweaver_default_sweaver_type() {

  $types = array();

  $type = new stdClass;
  $type->api_version = 1;
  $type->disabled = FALSE;
  $type->name = 'machine_name';
  $type->description = 'Description';
  $type->type_options = array(
    'property_1' => 'property_1',
    'property_2' => 'property_2',
    'property_3' => 'property_2',
  );
  $types['machine_name'] = $type;
  
  return $types;
}


---------------------------------------------------------
3. Plugins hook.
---------------------------------------------------------

/**
 * Implementation of hook_sweaver_plugins().
 */
function hook_sweaver_plugins() {
  $plugins = array();
  
  $plugins['yourpluginname'] = array(
    'handler' => array(
      'tab' => t('Tab name'), // If you want to do something in the frontend of course.
      'tab_description' => t('Description of your plugin in frontend'),
      'path' => drupal_get_path('module', 'yourmodulename') .'/plugins/yourpluginname',
      'file' => 'yourpluginname.inc',
      'class' => 'yourclassnameusuallythesameasyourpluginname',
      'parent' => 'sweaver_plugin', // This is required.
    ),
  );
  
  return $plugins;
}

---------------------------------------------------------
4. Plugin class example.
---------------------------------------------------------

/**
 * Your plugin
 *
 * All methods are optional.
 */
class pluginname extends sweaver_plugin {

  /**
   * Return module dependencies.
   */
  function sweaver_dependencies() {
    return array('module');
  }

  /**
   * Menu registry.
   */
  function sweaver_menu(&$weight, $page_arguments, $base) {
    // $page_arguments = array('plugin' => 'name_of_your_plugin'); 
    //  $base = array(
    //    'access arguments' => array('configure sweaver'),
    //    'page callback' => 'sweaver_menu_callback',
    //  );
    // You can use these to add to your menu items.
    // Other stuff you can return in page arguments:
    // callback_method: defaults to sweaver_menu_callback - optional.
    // return_method : default to drupal_get_form - optional
    // Return menu items for Drupal.
  }

  /**
   * Theme registry.
   */
  function sweaver_theme() {
    // Return theming functions for Drupal.
  }

  /**
   * Init function.
   */
  function sweaver_init() {
    // Do stuff during hook_init() of Drupal.
  }

  /**
   * Sweaver objects alter.
   */
  function sweaver_objects_alter(&$objects) {}

  /**
   * Sweaver form.
   */
  function sweaver_form() {
    return array();
  }

  /**
   * Sweaver form render.
   */
  function sweaver_form_render(&$vars, &$form, $plugin) {
    // Do some extra rendering on the form.
  }

  /**
   * Frontend css and js.
   */
  function sweaver_form_css_js(&$inline_settings) {
    // Add css, js and manipulate the inline settings of sweaver.
  }

  /**
   * Frontend form submit.
   */
  function sweaver_form_submit($form, &$form_state) {
    // Do something with the submitted values.
  }
  
  /**
   * Default menu callback.
   */
  function sweaver_menu_callback() {
    // Return a form or simply some other output.
    // Must return a form array() by default. This
    // is the default method you need to implement.
    // This makes is possible to have menu callbacks in your
    // class without having to create a new file.
    // All plugins - except for editor.admin.inc' use this
    // technique. See sweaver_menu_callback() for options.
  }

  /**
   * Default sweaver menu callback validate.
   */
  function sweaver_menu_callback_validate($form, &$form_state) {
    // Validate the submission.
  }

  /**
   * Default sweaver menu callback submit
   */
  function sweaver_menu_callback_submit($form, &$form_state) {
    // Do something with the submitted values.
  }
}

------------------------------------------------------
5. sweaver_get_plugin().
------------------------------------------------------

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

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

------------------------------------------------------
6. Images handler.
------------------------------------------------------

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

myclass extends sweaver_plugin {
  function sweaver_images_handler(&$images) {
    $images['file_path_1'] = 'Real name 1'; 
    $images['file_path_2'] = 'Real name 2'; 
  }
}

------------------------------------------------------
7. Session handling
------------------------------------------------------

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

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

------------------------------------------------------
8. Sweaver popups.
------------------------------------------------------

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

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

------------------------------------------------------
9. General functions.
------------------------------------------------------

- sweaver_get_current_style($reset = FALSE) {}
  Returns the css for the theme.
- sweaver_get_theme_info($theme) {}
  Returns the theme info for the theme.

------------------------------------------------------
10. General JS functions.
------------------------------------------------------

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

- HOOK_updateCss() {} 
  Must a return CSS definitions to write for the editor.
  Implemented in editor and custom css plugin. You must add the plugin
  in the sweaver_form_css_js method in the inline_settings variable in 
  key 'invokes'. See plugins/sweaver_custom_css/sweaver_custom_css.inc.
- Drupal.Sweaver.switchTab(remove_tab, show_tab) {}
  Switch to a tab in the editor
- Drupal.Sweaver.setMessage(messages) {}
  Sets a message above the editor. Times out after 5 seconds.
- Drupal.Sweaver.showPopup(message) {}
  Shows a popup screen with any content you like. 
  Gets a close button.
- Drupal.Sweaver.hidePopup() {}
  Closes the popup screen.

------------------------------------------------------
11. General CSS styles.
------------------------------------------------------

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

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

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

The variable in the database is 'sweaver_skin'.

------------------------------------------------------
13. Theme extensions.
------------------------------------------------------

1. Palettes

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

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

sweaver[palettes][pink][name] = Pink
sweaver[palettes][pink][file] = palettes/pink.css
sweaver[palettes][pink][colors][] = #f98cf0
sweaver[palettes][pink][colors][] = #af63a9
sweaver[palettes][pink][colors][] = #af63a9
sweaver[palettes][pink][colors][] = #cbb2c9
sweaver[palettes][pink][colors][] = #cbb2c9 

2. Selectors

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

sweaver[selectors][body] = Body
sweaver[selectors][h1] = Heading 1
...

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

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

------------------------------------------------------
14. hook_sweaver_action($action, $arguments).
------------------------------------------------------

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

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

File

API.txt
View source
  1. Table of contents
  2. ------------------
  3. 1. Hook for cTools.
  4. 2. Hooks for registering selectors, properties and types.
  5. 3. Plugins hook.
  6. 4. Plugin class example.
  7. 5. sweaver_get_plugin().
  8. 6. Images handler.
  9. 7. Session handling
  10. 8. Sweaver popups.
  11. 9. General functions.
  12. 10. General JS functions.
  13. 11. General CSS styles.
  14. 12. Skins
  15. 13. Theme extensions.
  16. 14. hook_sweaver_action().
  17. ------------------------------------------------------
  18. 1. Hook for cTools
  19. ------------------------------------------------------
  20. /**
  21. * Implementation of hook_ctools_plugin_api().
  22. */
  23. function hook_ctools_plugin_api($owner, $api) {
  24. if ($owner == 'sweaver' && $api == 'sweaver') {
  25. return array('version' => 1);
  26. }
  27. }
  28. ---------------------------------------------------------
  29. 2. Hooks for registering selectors, properties and types
  30. ---------------------------------------------------------
  31. /**
  32. * Implementation of hook_default_sweaver_selector().
  33. */
  34. function hook_default_sweaver_selector() {
  35. $selectors = array();
  36. $selector = new stdClass;
  37. $selector->api_version = 1;
  38. $selector->disabled = FALSE; // Set this to true if you want to disable this by default.
  39. $selector->name = 'machine_name';
  40. $selector->description = 'Description';
  41. $selector->selector_selector = '.selector'; // css selector.
  42. $selector->selector_highlight = FALSE; // Whether to highlight the selector in the active path.
  43. $selectors['machine_name'] = $selector;
  44. return $selectors;
  45. }
  46. /**
  47. * Implementation of hook_default_sweaver_property().
  48. */
  49. function hook_default_sweaver_property() {
  50. $propertys = array();
  51. // Font.
  52. $property = new stdClass;
  53. $property->api_version = 1;
  54. $property->disabled = FALSE; // Set this to true if you want to disable this by default.
  55. $property->name = 'machine_name';
  56. $property->description = 'Description';
  57. $property->property = ''; // The actual css property. Seperate multiple values by spaces.
  58. $property->property_parent = ''; // Wether this property has a parent.
  59. $property->property_type = 'select'; // Can be select, slider, image, color or parent.
  60. // Prefix or suffix: eg: padding has suffix 'px', url has prefix 'url(' and suffix ');'
  61. $property->property_prefix = '';
  62. $property->property_suffix = '';
  63. // Slider min & max - only applicable for slider.
  64. $property->property_slider_min = ''; // Minimum for slider , usually 1.
  65. $property->property_slider_max = ''; // Maximum for slider
  66. // Options are only applicable for select.
  67. $property->property_options = array(
  68. 'option_1' => 'Readable option 1',
  69. 'option_2' => 'Readable option 2',
  70. 'option_2' => 'Readable option 3',
  71. );
  72. $propertys['font-machine_name'] = $property;
  73. // Yes you need to return propertys, that's the way Ctools works :)
  74. return $propertys;
  75. }
  76. /**
  77. * Implementation of hook_sweaver_type().
  78. */
  79. function sweaver_default_sweaver_type() {
  80. $types = array();
  81. $type = new stdClass;
  82. $type->api_version = 1;
  83. $type->disabled = FALSE;
  84. $type->name = 'machine_name';
  85. $type->description = 'Description';
  86. $type->type_options = array(
  87. 'property_1' => 'property_1',
  88. 'property_2' => 'property_2',
  89. 'property_3' => 'property_2',
  90. );
  91. $types['machine_name'] = $type;
  92. return $types;
  93. }
  94. ---------------------------------------------------------
  95. 3. Plugins hook.
  96. ---------------------------------------------------------
  97. /**
  98. * Implementation of hook_sweaver_plugins().
  99. */
  100. function hook_sweaver_plugins() {
  101. $plugins = array();
  102. $plugins['yourpluginname'] = array(
  103. 'handler' => array(
  104. 'tab' => t('Tab name'), // If you want to do something in the frontend of course.
  105. 'tab_description' => t('Description of your plugin in frontend'),
  106. 'path' => drupal_get_path('module', 'yourmodulename') .'/plugins/yourpluginname',
  107. 'file' => 'yourpluginname.inc',
  108. 'class' => 'yourclassnameusuallythesameasyourpluginname',
  109. 'parent' => 'sweaver_plugin', // This is required.
  110. ),
  111. );
  112. return $plugins;
  113. }
  114. ---------------------------------------------------------
  115. 4. Plugin class example.
  116. ---------------------------------------------------------
  117. /**
  118. * Your plugin
  119. *
  120. * All methods are optional.
  121. */
  122. class pluginname extends sweaver_plugin {
  123. /**
  124. * Return module dependencies.
  125. */
  126. function sweaver_dependencies() {
  127. return array('module');
  128. }
  129. /**
  130. * Menu registry.
  131. */
  132. function sweaver_menu(&$weight, $page_arguments, $base) {
  133. // $page_arguments = array('plugin' => 'name_of_your_plugin');
  134. // $base = array(
  135. // 'access arguments' => array('configure sweaver'),
  136. // 'page callback' => 'sweaver_menu_callback',
  137. // );
  138. // You can use these to add to your menu items.
  139. // Other stuff you can return in page arguments:
  140. // callback_method: defaults to sweaver_menu_callback - optional.
  141. // return_method : default to drupal_get_form - optional
  142. // Return menu items for Drupal.
  143. }
  144. /**
  145. * Theme registry.
  146. */
  147. function sweaver_theme() {
  148. // Return theming functions for Drupal.
  149. }
  150. /**
  151. * Init function.
  152. */
  153. function sweaver_init() {
  154. // Do stuff during hook_init() of Drupal.
  155. }
  156. /**
  157. * Sweaver objects alter.
  158. */
  159. function sweaver_objects_alter(&$objects) {}
  160. /**
  161. * Sweaver form.
  162. */
  163. function sweaver_form() {
  164. return array();
  165. }
  166. /**
  167. * Sweaver form render.
  168. */
  169. function sweaver_form_render(&$vars, &$form, $plugin) {
  170. // Do some extra rendering on the form.
  171. }
  172. /**
  173. * Frontend css and js.
  174. */
  175. function sweaver_form_css_js(&$inline_settings) {
  176. // Add css, js and manipulate the inline settings of sweaver.
  177. }
  178. /**
  179. * Frontend form submit.
  180. */
  181. function sweaver_form_submit($form, &$form_state) {
  182. // Do something with the submitted values.
  183. }
  184. /**
  185. * Default menu callback.
  186. */
  187. function sweaver_menu_callback() {
  188. // Return a form or simply some other output.
  189. // Must return a form array() by default. This
  190. // is the default method you need to implement.
  191. // This makes is possible to have menu callbacks in your
  192. // class without having to create a new file.
  193. // All plugins - except for editor.admin.inc' use this
  194. // technique. See sweaver_menu_callback() for options.
  195. }
  196. /**
  197. * Default sweaver menu callback validate.
  198. */
  199. function sweaver_menu_callback_validate($form, &$form_state) {
  200. // Validate the submission.
  201. }
  202. /**
  203. * Default sweaver menu callback submit
  204. */
  205. function sweaver_menu_callback_submit($form, &$form_state) {
  206. // Do something with the submitted values.
  207. }
  208. }
  209. ------------------------------------------------------
  210. 5. sweaver_get_plugin().
  211. ------------------------------------------------------
  212. .You can use sweaver_get_plugin to get an object. This function will
  213. load the plugin and return the class if found.
  214. $object = sweaver_get_plugin('plugin_name');
  215. $object->do_some_method();
  216. ------------------------------------------------------
  217. 6. Images handler.
  218. ------------------------------------------------------
  219. The editor searches for a class which implements a method called sweaver_images_handler.
  220. By default, the images plugin which comes in the sweaver module provides extra images.
  221. You can change this by setting the variable 'sweaver_plugin_handle_images' to the name
  222. of the plugin you want. The plugin itself must implement following method:
  223. myclass extends sweaver_plugin {
  224. function sweaver_images_handler(&$images) {
  225. $images['file_path_1'] = 'Real name 1';
  226. $images['file_path_2'] = 'Real name 2';
  227. }
  228. }
  229. ------------------------------------------------------
  230. 7. Session handling
  231. ------------------------------------------------------
  232. sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return = 'string')
  233. Set or return session variables which you can easily use througout the plugin system.
  234. Much easier than using $_SESSION variables. This function does it all for you.
  235. Use it as much as you can.
  236. ------------------------------------------------------
  237. 8. Sweaver popups.
  238. ------------------------------------------------------
  239. You can put forms in a sweaver popup, which we do for example in the themesettings plugin.
  240. Following things in the sweaver_form method will make sure this happens:
  241. $form['#popups'] = array(); // Initialize the popups array.
  242. $form['#popups'][] = $key; // Put a FAPI key in the popups array.
  243. // Link class: popup-link This will trigger the popup.
  244. // The link needs an id with at least 'link' in the name. The form
  245. // it has to show needs the same id, but with 'link' replaced as 'data'.
  246. For inspiration, take a look at plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc.
  247. ------------------------------------------------------
  248. 9. General functions.
  249. ------------------------------------------------------
  250. - sweaver_get_current_style($reset = FALSE) {}
  251. Returns the css for the theme.
  252. - sweaver_get_theme_info($theme) {}
  253. Returns the theme info for the theme.
  254. ------------------------------------------------------
  255. 10. General JS functions.
  256. ------------------------------------------------------
  257. There are a couple of JS functions you can use in your plugins.
  258. - HOOK_updateCss() {}
  259. Must a return CSS definitions to write for the editor.
  260. Implemented in editor and custom css plugin. You must add the plugin
  261. in the sweaver_form_css_js method in the inline_settings variable in
  262. key 'invokes'. See plugins/sweaver_custom_css/sweaver_custom_css.inc.
  263. - Drupal.Sweaver.switchTab(remove_tab, show_tab) {}
  264. Switch to a tab in the editor
  265. - Drupal.Sweaver.setMessage(messages) {}
  266. Sets a message above the editor. Times out after 5 seconds.
  267. - Drupal.Sweaver.showPopup(message) {}
  268. Shows a popup screen with any content you like.
  269. Gets a close button.
  270. - Drupal.Sweaver.hidePopup() {}
  271. Closes the popup screen.
  272. ------------------------------------------------------
  273. 11. General CSS styles.
  274. ------------------------------------------------------
  275. There are several css classes which you can use which will do all kinds of stuff
  276. - popup-link: put this on a link and this will trigger a sweaver popup
  277. - sweaver-switch-to-style: adds a brush icon
  278. - container: lets a div float
  279. - container-1 to container-4: determines the width (from 25% to 100%)
  280. - float-left: floats to left
  281. - form-floater: makes form items and submits float
  282. ------------------------------------------------------
  283. 12. Skins.
  284. ------------------------------------------------------
  285. You can create new skins for the editor if you like. Simply
  286. create a new directory with your name and copy the files which
  287. are found in default, rename them to the name of your new skin
  288. and adjust them to your likings. On the general configuration screen,
  289. you can select the skin you like.
  290. The variable in the database is 'sweaver_skin'.
  291. ------------------------------------------------------
  292. 13. Theme extensions.
  293. ------------------------------------------------------
  294. 1. Palettes
  295. Every theme can define color palettes. These palettes are
  296. extra css files that can be added to your theme and that
  297. overwrite the default css.
  298. You can add a palette and 5 preview colors in your .info file, e.g.:
  299. sweaver[palettes][pink][name] = Pink
  300. sweaver[palettes][pink][file] = palettes/pink.css
  301. sweaver[palettes][pink][colors][] = #f98cf0
  302. sweaver[palettes][pink][colors][] = #af63a9
  303. sweaver[palettes][pink][colors][] = #af63a9
  304. sweaver[palettes][pink][colors][] = #cbb2c9
  305. sweaver[palettes][pink][colors][] = #cbb2c9
  306. 2. Selectors
  307. You can also define selectors per theme in the info file, eg:
  308. sweaver[selectors][body] = Body
  309. sweaver[selectors][h1] = Heading 1
  310. ...
  311. The order is how you define it in the info file.
  312. In the backend you can select if these selectors
  313. are to be used instead of those in the database.
  314. Note: if you add new theme extensions but they don't show up,
  315. then you need to clear the theme registry.
  316. ------------------------------------------------------
  317. 14. hook_sweaver_action($action, $arguments).
  318. ------------------------------------------------------
  319. If you want other modules to act on certain actions happening in sweaver use
  320. module_invoke_all('sweaver', 'action_name', $arguments);
  321. Currently the Theme switch plugin is the first plugin calling this
  322. so other modules can perform actions when switching theme.