fullcalendar.api.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the FullCalendar module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Constructs CSS classes for an entity.
  12. *
  13. * @param object $entity
  14. * Object representing the entity.
  15. *
  16. * @return array
  17. * Array of CSS classes.
  18. */
  19. function hook_fullcalendar_classes($entity) {
  20. // Add the entity type as a class.
  21. return array(
  22. $entity->entity_type,
  23. );
  24. }
  25. /**
  26. * Alter the CSS classes for an entity.
  27. *
  28. * @param array $classes
  29. * Array of CSS classes.
  30. * @param object $entity
  31. * Object representing the entity.
  32. */
  33. function hook_fullcalendar_classes_alter(&$classes, $entity) {
  34. // Remove all classes set by modules.
  35. $classes = array();
  36. }
  37. /**
  38. * Declare that you provide a droppable callback.
  39. *
  40. * Implementing this hook will cause a checkbox to appear on the view settings,
  41. * when checked FullCalendar will search for JS callbacks in the form
  42. * Drupal.fullcalendar.droppableCallbacks.MODULENAME.callback.
  43. *
  44. * @see http://arshaw.com/fullcalendar/docs/dropping/droppable
  45. */
  46. function hook_fullcalendar_droppable() {
  47. // This hook will never be executed.
  48. return TRUE;
  49. }
  50. /**
  51. * Allows your module to affect the editability of the calendar.
  52. *
  53. * If any module implementing this hook returns FALSE, the value will be set to
  54. * FALSE. Use hook_fullcalendar_editable_alter() to override this if necessary.
  55. *
  56. * @param object $entity
  57. * Object representing the entity.
  58. * @param object $view
  59. * Object representing the view.
  60. *
  61. * @return bool
  62. * A Boolean value dictating whether of not the calendar is editable.
  63. */
  64. function hook_fullcalendar_editable($entity, $view) {
  65. return _fullcalendar_update_access($entity);
  66. }
  67. /**
  68. * Allows your module to forcibly override the editability of the calendar.
  69. *
  70. * @param bool $editable
  71. * A Boolean value dictating whether of not the calendar is editable.
  72. * @param object $entity
  73. * Object representing the entity.
  74. * @param object $view
  75. * Object representing the view.
  76. */
  77. function hook_fullcalendar_editable_alter(&$editable, $entity, $view) {
  78. $editable = FALSE;
  79. }
  80. /**
  81. * Alter the dates after they're loaded, before they're added for rendering.
  82. *
  83. * @param object $date1
  84. * The start date object.
  85. * @param object $date2
  86. * The end date object.
  87. * @param array $context
  88. * An associative array containing the following key-value pairs:
  89. * - instance: The field instance.
  90. * - entity: The entity object for this date.
  91. * - field: The field info.
  92. */
  93. function hook_fullcalendar_process_dates_alter(&$date1, &$date2, $context) {
  94. // Always display dates only on one day.
  95. if ($date1->format(DATE_FORMAT_DATE) != $date2->format(DATE_FORMAT_DATE)) {
  96. $date2 = $date1;
  97. }
  98. }
  99. /**
  100. * Defines the location of your FullCalendar API includes.
  101. *
  102. * @return array
  103. * An associative array containing the following key-value pairs:
  104. * - api: The version of the FullCalendar API your module implements.
  105. * - path: The location of your MODULENAME.fullcalendar.inc files.
  106. */
  107. function hook_fullcalendar_api() {
  108. return array(
  109. 'api' => fullcalendar_api_version(),
  110. 'path' => drupal_get_path('module', 'MODULENAME') . '/includes',
  111. );
  112. }
  113. /**
  114. * Declares your FullCalendar configuration extender.
  115. *
  116. * @return array
  117. * An associative array, keyed by your module's machine name, containing an
  118. * associative array with the following key-value pairs:
  119. * - name: The translated name of your module.
  120. * - parent: (optional) The machine name of your module if you are providing
  121. * functionality on behalf of another module.
  122. * - css: (optional) TRUE if the module provides a CSS file.
  123. * - js: (optional) TRUE if the module provides a JS file.
  124. * - weight: (optional) A number defining the order in which the includes are
  125. * processed and added to the form.
  126. * - no_fieldset: (optional) TRUE if the module provides its own fieldset.
  127. */
  128. function hook_fullcalendar_options_info() {
  129. // Colorbox integration is currently provided by fullcalendar_options, and it
  130. // provides a JS file.
  131. return array(
  132. 'colorbox' => array(
  133. 'name' => t('Colorbox'),
  134. 'js' => TRUE,
  135. 'parent' => 'fullcalendar_options',
  136. ),
  137. );
  138. }
  139. /**
  140. * Return an array to be added to FullCalendar's Views option definition.
  141. *
  142. * @return array
  143. * An associative array in the form expected by Views option_definition().
  144. * For usage in this context, it will generally be an associative array keyed
  145. * by the module name, containing an associative array with the key
  146. * 'contains', which contains an associative array with the following
  147. * key-value pairs:
  148. * - default: The default value for this item.
  149. * - bool: (optional) Whether or not the value is a Boolean.
  150. *
  151. * @see views_object::option_definition()
  152. */
  153. function hook_fullcalendar_options_definition() {
  154. $options['colorbox']['contains'] = array(
  155. 'colorbox' => array(
  156. 'default' => FALSE,
  157. 'bool' => TRUE,
  158. ),
  159. 'colorboxIFrame' => array(
  160. 'default' => FALSE,
  161. 'bool' => TRUE,
  162. ),
  163. 'colorboxClass' => array('default' => '#content'),
  164. 'colorboxWidth' => array('default' => '80%'),
  165. 'colorboxHeight' => array('default' => '80%'),
  166. );
  167. return $options;
  168. }
  169. /**
  170. * Return an array to be added to FullCalendar's Views options form.
  171. *
  172. * @param array $form
  173. * The FullCalendar style plugin options form structure.
  174. * @param array $form_state
  175. * The FullCalendar style plugin options form state.
  176. * @param object $view
  177. * The FullCalendar view object.
  178. *
  179. * @see views_object::options_form()
  180. */
  181. function hook_fullcalendar_options_form(&$form, &$form_state, &$view) {
  182. $form['colorbox']['colorbox'] = array(
  183. '#type' => 'checkbox',
  184. '#title' => t('Open events with Colorbox'),
  185. '#default_value' => $view->options['colorbox']['colorbox'],
  186. );
  187. $form['colorbox']['colorboxIFrame'] = array(
  188. '#type' => 'checkbox',
  189. '#title' => t('Open events in iFrame'),
  190. '#default_value' => $view->options['colorbox']['colorboxIFrame'],
  191. );
  192. $form['colorbox']['colorboxClass'] = array(
  193. '#type' => 'textfield',
  194. '#title' => t('Classname or ID selector'),
  195. '#default_value' => $view->options['colorbox']['colorboxClass'],
  196. );
  197. $form['colorbox']['colorboxWidth'] = array(
  198. '#type' => 'textfield',
  199. '#title' => t('Width'),
  200. '#default_value' => $view->options['colorbox']['colorboxWidth'],
  201. );
  202. $form['colorbox']['colorboxHeight'] = array(
  203. '#type' => 'textfield',
  204. '#title' => t('Height'),
  205. '#default_value' => $view->options['colorbox']['colorboxHeight'],
  206. );
  207. $form['sameWindow']['#dependency'] = array('edit-style-options-colorbox-colorbox' => array(0));
  208. }
  209. /**
  210. * Allows validation of the FullCalendar Views options form.
  211. *
  212. * @param array $form
  213. * The FullCalendar style plugin options form structure.
  214. * @param array $form_state
  215. * The FullCalendar style plugin options form state.
  216. * @param object $view
  217. * The FullCalendar view object.
  218. *
  219. * @see views_object::options_validate()
  220. */
  221. function hook_fullcalendar_options_validate(&$form, &$form_state, &$view) {
  222. if (!is_numeric($form_state['values']['style_options']['example']['number'])) {
  223. form_error($form['example']['number'], t('!setting must be numeric.', array('setting' => 'Number')));
  224. }
  225. }
  226. /**
  227. * Allows custom submission handling for the FullCalendar Views options form.
  228. *
  229. * @param array $form
  230. * The FullCalendar style plugin options form structure.
  231. * @param array $form_state
  232. * The FullCalendar style plugin options form state.
  233. * @param object $view
  234. * The FullCalendar view object.
  235. *
  236. * @see views_object::options_submit()
  237. */
  238. function hook_fullcalendar_options_submit($form, &$form_state, $view) {
  239. $options = &$form_state['values']['style_options'];
  240. unset($options['my_unwanted_setting']);
  241. }
  242. /**
  243. * Allow any modules to have access to the view after the query is run.
  244. *
  245. * @param array $variables
  246. * The variables array, containing the view object.
  247. * @param array $settings
  248. * An array of settings to be passed to JavaScript.
  249. */
  250. function hook_fullcalendar_options_process(&$variables, &$settings) {
  251. $view = &$variables['view'];
  252. $view->my_setting = TRUE;
  253. }
  254. /**
  255. * Allow any modules to have access to the view before the query is run.
  256. *
  257. * @param array $settings
  258. * An array of settings to be passed to JavaScript.
  259. * @param object $view
  260. * The FullCalendar view object.
  261. */
  262. function hook_fullcalendar_options_pre_view(&$settings, &$view) {
  263. $settings['my_setting'] = array(
  264. 'my_other_setting' => $settings['my_other_setting'],
  265. 'my_another_setting' => $settings['my_another_setting'],
  266. );
  267. }
  268. /**
  269. * @} End of "addtogroup hooks".
  270. */