When you save a node in Drupal 7, hook_node_presave is there to modify values before the node is saved. Also available are the 'original' values so you can compare values from before the edit to after the edit. Can come in handy if you need to trigger some processes when values are changed...
Read more
Add your own custom user permissions in Drupal 7
Say you created a module that has a page that only certain user roles should be able to access. If you're not using Panels/Page Manager (which can limit per user role) and you're using your own hook_menu item, you'll need to come up with your own permission that will show up on /admin/people/permissions. ...
Read more
Using db_select with conditional statements in Drupal 7
While the debate never ends about using db_select versus db_query...some say db_select is slower and db_query should be used for simple queries, but there are obvious advantages to db_select with its extenders and much more.
Whatever your decision, here is one case where db_select is super nice. Instead of building the query string in a variable...
Read more
Allow other functions to alter your data in Drupal 7
You created a function and maybe you want other modules to be able to go in and modify data as needed. Maybe you're returning a list of links and you want other modules to add their own links if needed. drupal_alter is one way of accomplishing this.
Read more
Using the Services module in Drupal 7 to create a REST API
Adding an API to your Drupal site doesn't have to be difficult, well...not too difficult. Using the Services module removes a lot of the work needed and sets you up for an easy implementation. Its especially nice with its hooks and it outputs everything in json format and handles error messaging.
I won't get...
Read more
Drupal caching with cache_get , cache_set , and cache_clear_all
We all know Drupal is a little 'heavy' when it comes to database queries. Using caching for some of your data can greatly improve load times and reduce server loads. Custom caching can be used for a variety of reasons. I like to use it for user-specific sections that Drupal doesn't like...
Read more
Using Batch API in Drupal 7 tutorial – in simple code
Finding a good tutorial about the batch API can be a little difficult. When you do, it may be a little difficult to understand. So here is my shot to try a simple tutorial. 4 simple functions you will need as a minimum:
Read more
- hook_menu to create the page
- callback function to run when page is...
Redirect a form after its submitted using Drupal 7
You created a form or want to redirect one of Drupal's form to another page based on a value/logic, you want to use hook_form_alter() to add your own submit function that runs when the form is submitted. You will be able to see the submitted form values and redirect as needed. Its a...
Read more