• 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.

  • Development

    Views Taxonomy: Get Terms with Associated Nodes

    This example serves as both an example of how to alter a Views2 query, as well as how to use the get_terms_by_count() function I’ve written.

    Unfortunately there is not (at present) a Views2 taxonomy filter that lets you “Get only terms with at least X associated nodes.” We had a client request that terms without associated nodes be hidden. This was actually more complex than it sounds, but the solution led me to a whole new level of Views2 understanding. Views2 has a hook called hook_views_query_alter() that lets you alter a Views2 query before it is executed. This is exactly what we needed to do in order to only pull terms with associated nodes. Specifically, we needed to add an additional WHERE clause to the query.

  • Development

    Rebuilding the Drupal Navigation Menu (Automatically)

    The following steps will get you a completely rebuilt Navigation menu.

    1. Clear your cache
    2. Backup your database
    3. In the database, remove any records in {menu_links} where menu_name = navigation
    4. Create a file somewhere in your site’s directory structure
    5. Add this code to that file and then save it
    6. Tell Drupal to ignore this file using this method.
    7. Browse to the file in your web browser (it will run quickly, with no indication of completion). Wait for the page to stop loading, then check your navigation menu settings in the admin.
    8. When finished, delete or make-inaccessible the PHP file you just made!
  • Development

    $user Conditionals

    This is one example of performing an action based on whether or not the current user belongs to a certain role or roles. Note that the admin user (UID #1) matches as well.

    Note: You may want to try using drupal_goto()  (or drupal_access_denied() in this case) instead of a header redirect.

  • Development

    Open All External Links in a New Window/Tab using jQuery

    … and to match two urls/domains/whatever: