skinr.api.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /**
  3. * @file
  4. * This file contains no working PHP code; it exists to provide additional documentation
  5. * for doxygen as well as to document hooks in the standard Drupal manner.
  6. */
  7. /**
  8. * @mainpage Skinr API Manual
  9. *
  10. * Topics:
  11. * - @ref skinr_hooks
  12. */
  13. /**
  14. * @defgroup skinr_hooks Skinrs hooks
  15. * @{
  16. * Hooks that can be implemented by other modules in order to implement the
  17. * Skinr API.
  18. */
  19. /**
  20. * Configure Skinr for this module.
  21. *
  22. * This hook should be placed in MODULENAME.skinr.inc and it will be auto-loaded.
  23. * This must either be in the same directory as the .module file or in a subdirectory
  24. * named 'includes'.
  25. *
  26. * @return
  27. * An array of element types this module supports.
  28. */
  29. function hook_skinr_config() {
  30. return array('block');
  31. }
  32. /**
  33. * Provide a list of all available theme hooks for a given element.
  34. *
  35. * @param $module
  36. * The module implementing given element.
  37. * @param $element
  38. * An element.
  39. *
  40. * @return
  41. * An array of theme hooks.
  42. */
  43. function hook_skinr_theme_hooks($module, $element) {
  44. $theme_hooks = array();
  45. if ($module == 'node') {
  46. $theme_hooks = array(
  47. 'node_' . $element,
  48. 'node',
  49. );
  50. }
  51. return $theme_hooks;
  52. }
  53. /**
  54. * Perform alterations to theme hooks before widgets are rendered.
  55. *
  56. * @param $theme_hooks
  57. * An array of theme hooks.
  58. * @param $module
  59. * The module implementing given element.
  60. * @param $element
  61. * An element.
  62. */
  63. function hook_skinr_theme_hooks_alter(&$theme_hooks, $module, $element) {
  64. if ($module == 'node') {
  65. array_unshift($theme_hooks, 'node_' . $element . '_custom');
  66. }
  67. }
  68. /**
  69. * Return an array of element ids.
  70. *
  71. * @todo Needs a better description.
  72. *
  73. * @param $variables
  74. * The variables array from skinr_preprocess().
  75. * @param $hook
  76. * The name of the theme hook.
  77. * @param $op
  78. * The operation being performed:
  79. * - 'preprocess'
  80. * - 'contextual_links'
  81. *
  82. * @return
  83. * An array of element arrays, keyed by element type. Example:
  84. * @code
  85. * array(
  86. * 'block' => array('system__navigation'),
  87. * );
  88. * @endcode
  89. *
  90. * @see skinr_preprocess()
  91. */
  92. function hook_skinr_elements(&$variables, $hook, $op) {
  93. $elements = array();
  94. if ($hook == 'block') {
  95. $elements['block'] = array($variables['block']->module . '__' . $variables['block']->delta);
  96. }
  97. return $elements;
  98. }
  99. /**
  100. * Define the API version of Skinr your code is compatible with.
  101. *
  102. * This is required when creating a new Skinr plugin. It checks to make sure
  103. * your Skins are compatible with the installed version of Skinr and takes care
  104. * of loading the include files.
  105. *
  106. * @return
  107. * An associative array describing Skinr API integration:
  108. * - directory: (optional) The name of a sub-directory, in which include files
  109. * containing skin or group definitions may be found.
  110. * - path: (optional) The path to the directory containing the directory
  111. * specified in 'directory'. Defaults to the path of the module or theme
  112. * implementing the hook.
  113. * In case no Skinr plugin include files exist for your implementation, simply
  114. * define the function with an empty function body.
  115. *
  116. * The "hook" prefix is substituted with the name of the module or theme that
  117. * implements it, e.g. THEME_skinr_api_VERSION() in template.php, or
  118. * MODULE_skinr_api_VERSION() in MODULE.module.
  119. *
  120. * VERSION is normally identical to Skinr's major version; e.g., "2".
  121. */
  122. function hook_skinr_api_VERSION() {
  123. return array(
  124. 'path' => drupal_get_path('module', 'mymodule'),
  125. 'directory' => 'skins',
  126. );
  127. }
  128. /**
  129. * Define the skin(s) for this Skinr plugin.
  130. *
  131. * Each skin definition consists of properties that define its form element and
  132. * settings that are needed to make it work, such as the class(es) Skinr should
  133. * apply, which files it should load, whether or not it should be disabled by
  134. * default and which theme hook(s) it was designed to work with.
  135. *
  136. * Each skin name must be unique. Skins cannot have the same name even if they
  137. * are located in different plugins. It is recommended to prefix the name of
  138. * each skin with the name of the theme or module implementing it.
  139. *
  140. * Skin settings:
  141. * - title (required): Title of the skin form element.
  142. * - description (optional): Description of the skin form element.
  143. * - group (optional): The group the skin is attached to; defaults to a Skinr
  144. * provided group labeled "General."
  145. * - type (optional): The type of form element. Allowed values:
  146. * - checkboxes (default): Useful when single or multiple options can be
  147. * chosen. This type does not need to be set manually. Skinr will apply
  148. * it by default.
  149. * - select: Useful when a single option can be chosen, but many exist.
  150. * - radios: Useful when a single option can be chosen and only a few options
  151. * exist.
  152. * - weight (discouraged): Sets the weight of the skin inside the group; NULL
  153. * by default. weight should not be set on each individual skin. Instead, it
  154. * should be used sparingly where positioning a skin at the very top or
  155. * bottom is desired.
  156. * - attached (optional): A array containing information about CSS and
  157. * JavaScript files the skin requires. Each entry is an array keyed by type:
  158. * - css (optional): Maps to the functionality of drupal_add_css() with one
  159. * exception: paths are automatically assumed relative to the plugin
  160. * directory, unless external. Examples:
  161. * - Simple:
  162. * 'css' => array('css/skin-name.css')
  163. * - Advanced:
  164. * 'css' => array(
  165. * array('css/skin-name-ie.css', array(
  166. * 'media' => 'screen',
  167. * 'browsers' => array('IE' => 'lte IE 8'),
  168. * ),
  169. * )
  170. * - js (optional): Maps to the functionality of drupal_add_js() with one
  171. * exception: paths are automatically assumed as relative to the plugin
  172. * directory, unless external. Examples:
  173. * - Simple:
  174. * 'js' => array('js/skin-name.js')
  175. * - Advanced:
  176. * 'js' => array(
  177. * array(
  178. * 'js/skin-name-advanced.js',
  179. * array(
  180. * 'scope' => 'footer',
  181. * 'group' => JS_THEME,
  182. * ),
  183. * )
  184. * - options (required): An array containing one or more options (also arrays)
  185. * for the user to choose from when applying skins. Each option key should be
  186. * a machine name describing the option. An option should including the
  187. * following keys:
  188. * - title (required): The option label.
  189. * - class (required): An array containing one or more classes the skin
  190. * should apply. All classes should be entered as an array: For example:
  191. * 'class' => array('class-b', 'class-b')
  192. * - attached (optional): Same syntax as above, but applies to a specific
  193. * option only.
  194. * - theme hooks (optional): An array containing certain allowed theme hooks,
  195. * which allow you to limit where the skin can be used. Allowed options
  196. * include: block, block__MODULE, comment_wrapper,comment__wrapper_NODETYPE,
  197. * node, node__NODETYPE, region, region__REGIONNAME, panels_display,
  198. * panels_region, panels_pane, views_view, views_view__STYLENAME,
  199. * views_view__DISPLAYNAME, and views_view__VIEWNAME.
  200. * - default status (optional): Skins are disabled by default to keep UI
  201. * clutter to a minimum. In some cases, like contrib themes, it makes sense to
  202. * enable skins which are required to make the theme work properly by default.
  203. * Setting this property to 1 will cause it to be enabled by default for all
  204. * installed themes.
  205. * - status: (optional) An associative array whose keys are theme names and
  206. * whose corresponding values denote the desired default status for the
  207. * particular theme.
  208. *
  209. * The "hook" prefix is substituted with the name of the module or theme
  210. * implementing it.
  211. */
  212. function hook_skinr_skin_info() {
  213. $skins['skinr_menus'] = array(
  214. 'title' => t('Menu styles'),
  215. 'description' => t('Select a style to use for the main navigation.'),
  216. 'type' => 'select',
  217. 'group' => 'skinr_menus',
  218. 'theme hooks' => array('block__menu', 'block__menu_block'),
  219. 'attached' => array(
  220. 'css' => array('css/nav.css'),
  221. ),
  222. 'options' => array(
  223. 'one_level' => array(
  224. 'title' => t('Standard (1 level) - No colors'),
  225. 'class' => array('nav'),
  226. ),
  227. 'menu_a' => array(
  228. 'title' => t('Standard (1 level) - Green'),
  229. 'class' => array('nav', 'nav-a'),
  230. 'attached' => array('css' => array('css/nav-colors.css')),
  231. ),
  232. 'menu_b' => array(
  233. 'title' => t('Standard (1 level) - Blue'),
  234. 'class' => array('nav', 'nav-b'),
  235. 'attached' => array('css' => array('css/nav-colors.css')),
  236. ),
  237. 'menu_c' => array(
  238. 'title' => t('Dropdowns - No colors'),
  239. 'class' => array('nav', 'nav-dd'),
  240. 'attached' => array(
  241. 'css' => array('css/nav-dd.css'),
  242. 'js' => array('js/dropdown.js'),
  243. ),
  244. ),
  245. 'menu_d' => array(
  246. 'title' => t('Dropdowns - Green'),
  247. 'class' => array('nav', 'nav-dd', 'nav-a'),
  248. 'attached' => array(
  249. 'css' => array('css/nav-dd.css'),
  250. 'js' => array('js/dropdown.js'),
  251. ),
  252. ),
  253. 'menu_e' => array(
  254. 'title' => t('Dropdowns - Blue'),
  255. 'class' => array('nav', 'nav-dd', 'nav-b'),
  256. 'attached' => array(
  257. 'css' => array('css/nav-dd.css'),
  258. 'js' => array('js/dropdown.js'),
  259. ),
  260. ),
  261. ),
  262. // Optional: Specify a global default status for this skin, making it
  263. // available or unavailable to all themes.
  264. 'default status' => 0,
  265. // Optional: Specify a default status for a particular theme. This mainly
  266. // makes sense for skins provided by themes only.
  267. 'status' => array(
  268. 'bartik' => 1,
  269. 'garland' => 0,
  270. // In case you are registering a skin for your base theme, then you likely
  271. // do not know which sub themes are going to use your base theme. By
  272. // setting the global default status to 0 (as above) and enabling the skin
  273. // for your base theme itself, the skin's status will be automatically
  274. // inherited to all sub themes of your base theme.
  275. 'mybasetheme' => 1,
  276. ),
  277. );
  278. return $skins;
  279. }
  280. /**
  281. * Define one or more skins in an atomic Skinr plugin file.
  282. *
  283. * This hook works identically to hook_skinr_skin_info(), but allows to place
  284. * one or more related skin definitions into a separate plugin file.
  285. *
  286. * For example, considering a module or theme with the name "extension" that
  287. * contains an include file:
  288. * @code
  289. * extension/skins/example/example.inc
  290. * @encode
  291. * The "hook" prefix is substituted with the name of the module or theme
  292. * implementing it ("extension"), and PLUGIN is substituted with the name of the
  293. * include file ("example"), e.g., THEME_skinr_skin_PLUGIN_info() or
  294. * MODULE_skinr_skin_PLUGIN_info(). For above example, the function name would
  295. * be: extension_skinr_skin_example_info().
  296. */
  297. function hook_skinr_skin_PLUGIN_info() {
  298. $skins['extension_example_menus'] = array(
  299. 'title' => t('Example menu styles'),
  300. 'type' => 'select',
  301. 'group' => 'skinr_menus',
  302. 'theme hooks' => array('block__menu', 'block__menu_block'),
  303. 'attached' => array(
  304. 'css' => array('css/nav.css'),
  305. ),
  306. 'options' => array(
  307. 'menu_a' => array(
  308. 'title' => t('Standard (1 level) - Green'),
  309. 'class' => array('nav', 'nav-a'),
  310. 'attached' => array('css' => array('css/nav-colors.css')),
  311. ),
  312. 'menu_b' => array(
  313. 'title' => t('Standard (1 level) - Blue'),
  314. 'class' => array('nav', 'nav-b'),
  315. 'attached' => array('css' => array('css/nav-colors.css')),
  316. ),
  317. ),
  318. );
  319. return $skins;
  320. }
  321. /**
  322. * Perform alterations on Skinr skins.
  323. *
  324. * @param $skins
  325. * An array of skin information exposed by hook_skinr_skin_info()
  326. * implementations.
  327. */
  328. function hook_skinr_skin_info_alter(&$skins) {
  329. // Remove restrictions on theme hooks the skin works with.
  330. unset($skins['skinr_menus']['theme hooks']);
  331. }
  332. /**
  333. * Defines group(s) that will contain skins.
  334. *
  335. * Groups are form element containers used to organize skins categorically. If
  336. * you do not define a group, your skins will appear in Skinr's default group,
  337. * which is labeled "General." Skinr implements 4 default groups, which may be
  338. * used in any skin implementation. For more information, see skins/default.inc.
  339. *
  340. * Each group name must be unique. It is recommended to prefix the name of each
  341. * group with the name of the theme or module name implementing it, followed by
  342. * the name of the group. Note that you cannot define 2 groups with the same
  343. * name, even if they are in different plugins.
  344. *
  345. * Group properties:
  346. * - title (required): Brief title of the tab.
  347. * - description (optional): Description of the group for administration page.
  348. * - weight (discouraged): Weight of the tab group; 0 by default.
  349. *
  350. * The "hook" prefix is substituted with the name of the module or theme that
  351. * implements it.
  352. *
  353. * @see skinr_default_skinr_group_info()
  354. */
  355. function hook_skinr_group_info() {
  356. $group['skinr_menus'] = array(
  357. 'title' => t('Menus'),
  358. 'description' => t('Menu and navigation styles.'),
  359. );
  360. return $groups;
  361. }
  362. /**
  363. * Define one or more skin groups in an atomic Skinr plugin file.
  364. *
  365. * This hook works identically to hook_skinr_group_info(), but allows to place
  366. * one or more related skin group definitions into a separate plugin file.
  367. *
  368. * For example, considering a module or theme with the name "extension" that
  369. * contains an include file:
  370. * @code
  371. * extension/skins/example/example.inc
  372. * @encode
  373. * The "hook" prefix is substituted with the name of the module or theme
  374. * implementing it ("extension"), and PLUGIN is substituted with the name of the
  375. * include file ("example"), e.g., THEME_skinr_group_PLUGIN_info() or
  376. * MODULE_skinr_group_PLUGIN_info(). For above example, the function name would
  377. * be: extension_skinr_group_example_info().
  378. */
  379. function hook_skinr_group_PLUGIN_info() {
  380. $group['extension_example_menus'] = array(
  381. 'title' => t('Menus'),
  382. 'description' => t('Menu and navigation styles.'),
  383. );
  384. return $groups;
  385. }
  386. /**
  387. * Perform alterations on Skinr groups.
  388. *
  389. * @param $groups
  390. * An array of group information exposed by hook_skinr_group_info()
  391. * implementations.
  392. */
  393. function hook_skinr_group_info_alter(&$groups) {
  394. // Show this tab group at the top of the Skinr settings form.
  395. $groups['skinr_menus']['weight'] = -1;
  396. }
  397. /**
  398. * @}
  399. */