Drupal – Clear cache from module

In Drupal, if you need to clear cache from your module then you can add this code when you need to clear cache. Mostly when we create a custom FORM to add/edit/delete anything other than node, we may need to clear cache.

Code:

function MODULENAME_flush_cache(){
  // this will clear any type of cache
  cache_clear_all(NULL, 'cache_block');
  cache_clear_all(NULL, 'cache_page');
  cache_clear_all('*', 'cache', TRUE);
  cache_clear_all('*', 'content', TRUE);
  cache_clear_all('*', 'cache_page', TRUE);
  cache_clear_all('*', 'cache_menu', TRUE);
  cache_clear_all('*', 'cache_filter', TRUE);
}
Advertisements

Drupal – Adding a clolor picker with your form item.

Drupal has its own color picker system. Drupal’s Farbtastic is very easy to add a color picker with your drupal form.

here is the code for your form item.

drupal_add_css('misc/farbtastic/farbtastic.css');
drupal_add_js('misc/farbtastic/farbtastic.js');
$form ['site_pagetitlecolor'] = array(
   '#type' => 'textfield',
   '#title' => t('Page Title Color'),
   '#default_value' => '#FFF',
   '#description' => '<div id="site_pagetitlecolor_colorpicker"></div>',
   '#size' => 9,
   '#maxlength' => 7,
   '#suffix' => "<script type='text/javascript'>
     $(document).ready(function() {
       $('#site_pagetitlecolor_colorpicker').farbtastic('#edit-site-pagetitlecolor');
     });
   </script>"
 );?

Adding this will provide your form item with a color picker.  :)

Modalbox comparison

Feature Overview

Module I GI IS HC IC V MS
Lightbox2 YES YES YES YES YES YES YES
jQuery Lightbox YES YES NO NO NO NO NO
Thickbox YES YES NO YES1 YES NO2 YES
Shadowbox YES YES YES YES YES YES YES3
Greybox Redux YES NO NO YES NO NO NO
I  = Images
GI = Grouped Images
IS = Image Slide show
HC = HTML Content
IC = Inline Content
V  = Videos
MS = Multilingual Support

Notes:

  1. Thickbox: the documentation says it supports HTML content via the use of iframes. While I managed to get this to work with some sites, it didn’t work with others including google.com. I believe this is because of the addition of GET parameters to the url.
  2. Thickbox: in theory it should be possible to view videos in a thickbox, but it’s not enough to just provide it with a link to a video. It works quite nicely with Embedded Media Field videos though where the emfield module creates the embed object and inserts it into thickbox’s iframe.
  3. Shadowbox: multilingual support is available in the 5.x-1.0 version. 5.x-2.0 moves language support from the module to Shadowbox itself and proper options will be added to allow translation in the near future. Multi-lingual support will be added to the 6.x-1.x-dev version when it has a full release.

For reference, “grouped images” means that you can group images together and manually navigate between them using “next” and “previous” buttons. A “slideshow” means it’s possible to group images together and have the browser automatically traverse through them without clicking any buttons, usually accompanied by a play/pause feature. “Video” support means either that they can display flash content in the lightbox or video in a player within the lightbox.

Source: drupal.org

Drupals – 81 points for Converting 5.x modules to 6.x

Overview of Drupal API changes in 6.x

1. Entirely new menu system
2. Major FormAPI improvements
3. New Schema API
4. New format for hook_install()
5. New format for hook_uninstall()
6. New format for hook_update_N()
7. The arguments to url() and l() have changed
8. Variable names can now be 128 characters long
9. Taxonomy terms are now associated with node revisions, not just nodes
10. format_plural() accepts replacements
11. New drupal_alter() function for developers
12. New module_load_include() and module_load_all_includes() functions for developers
13. hook_form_alter() parameters have changed
14. hook_link_alter() parameters have changed
15. hook_profile_alter() parameters have changed
16. hook_mail_alter() parameters have changed
17. $locale became $language
18. New hook_theme() registry
19. template_preprocess_* with .tpl.php files
20. node/add is now menu generated
21. New watchdog hook, logging and alerts
22. Parameters of watchdog() changed
23. new hook_update_N naming convention
24. New syntax for .info files
25. Core compatibility now specified in .info files
26. PHP compatibility now specified in .info files
27. New db_column_exists() method
28. cache_set parameter order has changed
29. Cache set and get automatically (un)serialize complex data types
30. node_revision_list() now returns keyed array
31. New operation in image.inc: image_scale_and_crop()
32. New user_mail_tokens() method
33. New ip_address() function when working behind proxies
34. {files} table changed
35. file_check_upload() merged into file_save_upload()
36. {file_revisions} table is now {upload}
37. drupal_add_css() supports automatic RTL CSS discovery
38. Node previews and adding form fields to the node form
39. JavaScript behaviors: new approach to attaching behaviors
40. JavaScript themeing
41. Translation of JavaScript files
42. JavaScript aggregation
43. custom_url_rewrite() replaced
44. hook_user(‘view’), hook_profile_alter() and profile theming
45. Distributed Authentication changes
46. hook_help() parameters are changed
47. Change “Submit” to “Save” on buttons
48. node_feed() parameters changed
49. hook_nodeapi(‘submit’) has been replaced by op=’presave’
50. taxonomy_get_vocabulary() changed to taxonomy_vocabulary_load()
51. hook_init() is split up into hook_init() and hook_boot()
52. Remove db_num_rows() method
53. Remove $row argument from db_result() method
54. Block-level caching
55. Batch operations : progressbar for heavy computations
56. Node access modules : simplified hook_enable / hook_disable / hook_node_access_records
57. node_access_rebuild($batch_mode = TRUE) / node_access_needs_rebuild()
58. Upgraded to jQuery 1.2.3
59. Removed several functions from drupal.js
60. The book module has been rewritten to use the new menu system
61. new helper function: db_placeholders()
62. Comment settings are now per node type
63. Check node access before emailing content
64. form property #DANGEROUS_SKIP_CHECK removed
65. “Access control” renamed to “permissions”
66. locale_refresh_cache() has been removed
67. FormAPI image buttons are now supported
68. db_next_id() is gone, and replaced as db_last_insert_id()
69. admin/logs renamed to admin/reports
70. New helper function: drupal_match_path()
71. drupal_mail() parameters have changed
72. New hook: hook_mail
73. Use drupal_set_breadcrumb() instead of menu_set_location() to set custom breadcrumbs
74. user_authenticate() changed parameters
75. Automatically add Drupal.settings.basePath
76. Get an object relevant on specific paths
77. hook_access() added parameter
78. Can’t add javascript or CSS to header in hook_footer()
79. Translations are looked for in ./translations
80. hook_submit() has been removed
81. hook_comment() no longer supports the ‘form’ operation, use hook_form_alter() instead