Code Examples About Drupal

Here you can find a list of code examples. Most are just documented functions. This is becoming my sort of personal code documentation repository. However, some examples have file attachments that you can download. All code exposed here is free and can be used without permission. No warranty is implied, but if you have questions about something, feel free to ask by posting a comment.

  • Pre-cached Ajax jQuery Thumbnail Carousel

    I recently got out of a war. A war with drupal, ajax, and jquery. I'd say, as lame as it sounds, this was the hardest dynamic javascript and ajax widget I've written. Here's the lowdown on the requirements and the solution:

  • Drupal Content Creation Checklist

    When creating a new node in drupal, it occurred to me that I do the same set of things every time. However, it seems like every time I go to do it again, I forget a step or two, and then I have to fix it later. I should just do it right up front. Here I'm going to list the set of steps I take to be thorough in my content creation.

  • apply_input_filter_rules

    Purpose: To auto set and hide drupal input format settings. The input format settings don't always makes sense to the uninitiated and so it's often nice to just set them and forget them for certain users. This function helps accomplish that, although it'll need to be customized for every unique situation.

    Description: Recursively finds specified input format fields in a drupal forms API array and auto sets them depending on configured rules. The rules are configured inside the function. It would be better to pull these rules out to make the function generic, but this is good enough for me for now. If someone else uses this function I'll probably make it more generic.

  • override_submit_buttons

    Purpose: Overrides drupal forms API submit buttons. Creates nice, rounded corner submit buttons using a hacky table tag. Sprinkle in imagery and css as necessary. It relies on a theme function called 'blank_image' that just renders a 1px X 1px transparent gif used to fill space so that the thing will work right in IE6.

    Description: This is a recursive funtion which searches through all the child elements of the current element. When it finds an element determined to be a button, it appends a link button at the end of the button. The link button will call the button's click() function on click. Therefore, it essentially replaces the button. We send down both the input form element and the link button so that we can degrade gracefully if the user doesn't have javascript.

  • get_node_context

    Purpose: To enable the code to find the node which is the main context of the page.

    Description: Gets the node that is the main context of the page. This is particularly useful when implementing drupal custom blocks in custom modules. You can easily get the node in context and do something relative to it in your custom block. This is very similar to og_get_group_context if you've ever used organic groups. Note that this function caches the nodes it finds so that it won't call node_load many times. This caching might be overkill tho.