• Development

    Get a List of Top-level Taxonomy Terms

    Quick Tip: Getting a list of taxonomy terms is easy using a view (type: Taxonomy). Trying to get only terms at the highest level is a bit trickier. One method I came up with is to add a Taxonomy: Parent term argument on the view. The key is to tell the argument to Provide default argument of PHP Code and set the value to  return 0;

    The result is that only top-level terms (terms without parents) are returned.

  • Development

    Showing a nodeasblock block as full content instead of teaser

    By default, the Node As Block module displays a node in teaser mode. If you wish to show the full content, add the following to your template.php file. (note I’ve also added an edit link for good measure)

  • Development

    Sending webform submissions to email based on value of field

    We recently did a site for a client that allowed patients to submit a webform to request an appointment. The user could choose their physician and based on their choice, the submission would be emailed to the chosen doctor’s secretary. I originally thought about using the key part of the key|value pair for the select list to store the secretary’s email address, with the doctor’s name. This wouldn’t work, however, because the key could not contain standard email address characters. The solution involved isn’t exactly dynamic, but for a select list that won’t change much (the case here), it’s a fairly elegant solution. Here is the select list and associated code. I created this with the webform UI using a simple select list webform field.

  • Development

    Using hook_form_alter() and #after_build to set maxlength on emvideo title field

    A fellow Drupal user posted an issue to the Embedded Media Field project. The user was trying to set the maxlength from 35 characters to some other number for the ‘title’ field within each embedded video widget. I faced the same issue with a site. The client wanted to be able to add more lengthy captions to each video they uploaded. I added the embedded video field (YouTube) as an “unlimited” video field.

    The solution involves using hook_form_alter() and the #after_build property.

     

  • Development

    Moving a field into a (different) group/fieldset using hook_form_alter()

    The following demonstrates how to move a field into a different fieldset within a form using hook_form_alter() and a special #after_build form property.

     

  • Development

    Show a timestamp as a date in the Drupal user’s timezone

     

  • Development

    db_query() and db_placeholders() example #1

    Have you ever wondered how to properly build a query like this in Drupal:

    This requires the use of db_placeholders() to create the placeholder ‘ ‘, ‘ ‘, etc.

    where $node_types is an array of node types.

  • Development

    Automatically create a Drupal node when a user registers

    Sometimes projects come up that have requirements that cannot be solved with an out-of-the-box Drupal install. A project I worked on some time ago required that I store a node every time a user registered for an account. The details of the project are a little fuzzy for me now, so I’ll just skip right to the example.

    This example shows how simple it is to programmatically create a node, and also shows the proper way to hook into the user system.

  • Development

    Make menu header a link to its first child link

    We use menu block a lot to create sidebar menus with specific depths, starting points, etc. The following snippet shows how we can use jQuery to turn a normal <h2> tag into a link. The link’s destination will be the same as the first child link.

    jquery_link

  • Development

    How to check if a jQuery plugin is loaded

    The following snippet is one way to determine if a jQuery plugin is loaded an available. There are probably other ways to achieve the same behavior, however this one never seems to fail me.