• 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

    Programmatically displaying an image using an imagecache preset

    The following illustrates one way to render an image using an Imagecache preset. Naturally, if your imagefield has multiple uploads you could wrap this in a foreach.

     

  • Development

    States in key|value format

    The following is a list of the United States in key|value format. It’s useful when creating a select list in Drupal.

  • Development

    Countries in key|value format

    The following is a list of countries in key|value format. It’s useful when creating a select list in Drupal.

  • Development

    Custom Voting API Calculation

    The Voting API is really nice when used in conjunction with a module like Fivestar. It takes all of the complexity out of setting up a voting/rating system. On occasion, however, you need it to do some things that aren’t built in. Using the VotingAPI’s API, I’ll show you how to trigger a function (send an email, write a message to the screen, etc.) when a piece of content receives a fifth vote of four stars or greater. That is, a node may have four votes of five stars, and two votes of two stars. As soon as the next greater-than-four vote goes in, we want to do something about it. In our case, the client wants to receive an email when a node is popular, and has had five four-star-or-greater votes.

  • Development

    Show Menu Description Field in Node Add/Edit Form

    Many components in Drupal have an optional title or description field. This text usually displays when a user hovers over an item. We had an interesting request: a client wanted to have a box that displayed text which would change every time you roll over a menu item. This can be accomplished using just a small amount of jQuery, and Drupal’s built-in menu handling. The menu system in Drupal can handle descriptions on each menu item, however you have to do this through the menu admin. The problem is that the client needed to be able to edit these descriptions at will.