• Development

    Pull Quotes via Custom Filters in Drupal 7

    UPDATE: This was a good solution, but I decided I wanted a little more flexibility in my filter (like being able to specify attributes in any order) and I wanted to get rid of the required [/pullquote] closing tag. Custom Filter has its limitations (and working through the gui would’ve been a PITA), so I fired up Vim and made a custom filter using hook_filter_info(). I encourage you to look at this new post: Pull Quotes in Drupal 7 – Using hook_filter_info()

    I’ve been working on a Drupal 7 site that requires some nicely-formatted pull quotes. The site editors need the ability to add them to their content easily through the “filtered” text fields throughout the site (e.g., body). After trying a few shortcode-type modules I decided I’d get the most flexibility and power out of a simple custom filter. If you haven’t checked out Custom Filter, you’ll want to familiarize yourself with this module before proceeding.

  • Development

    Drupal Quick Tip: Easier “Archive” Filtering

    I was working on a project today where we needed to show an archive of announcement nodes. The sidebar had to show a listing of months like this:

    archive

    This is easy to accomplish by using the default Archive view that ships with Views, or by creating your own view that uses the same contextual filters, block and page. The contextual filter most typically used is Content: Created year + month. Here’s what the settings look like for this contextual filter:

  • Development

    Overriding Image Field Attribute Forms

    Another quick example for you…

    Here’s what the default image field form looks like, if you have enabled alt and title attributes:

    image_field_before

    One way to modify the titles and help text (descriptions) of the Alternate text and Title attributes here is to use hook_field_widget_form_alter. Here’s what your code might look like:

    Here’s the result:

    image_field_after

     

     

  • Development

    Sorting by Specific Fields with Apache Solr

    Recently I had to configure an Apache Solr search page to have the results sorted by a date field. We’re using the apachesolr module, which has a number of useful hooks, two of which we’ll use to accomplish this custom sort.

    If you browse to Administration » Reports » Apache Solr search index you will see a list of the indexed fields (example shown below). Most of the documentation I’ve seen out there regarding apachesolr sorting says you can use $query->setAvailableSort()  and $query->setSolrSort() within an implementation of  hook_apachesolr_query_prepare() , but there is at least one caveat: the field you want to sort on must be a single-value field! Here’s a look at the field list on the site I’m working on:

    apachesolr_fields

  • Uncategorized

    Creating Field Groups in a Custom Module

    If you need your module to add a fieldgroup to your Drupal 7 site, follow this quick and easy process: Also, if you’re looking to create fields, see this related post.

    1. Build the fieldgroup through the “manage fields” UI.
    2. Modify the code below to include a proper $fieldgroup_name, $entity_type and $bundle_name. I needed to add a field to the user profile, so I set the $entity_type to “user” and the $bundle_name to “user”.
  • Development

    Creating Fields in a Custom Module

    I’m going to be very brief here, because Joel Stein covers this beautifully. Also, if you’re looking to create fieldgroups, see this related post.
    If you need your module to add a field to your Drupal 7 site, follow this quick and easy process:

    1. Build the field through the “manage fields” UI.
    2. Modify the code below to include a proper $field_name, $entity_type and $bundle_name. I needed to add a field to the user profile, so I set the $entity_type to “user” and the $bundle_name to “user”.
  • Development

    Quick Tip: Using Markdown Filter with SyntaxHighlighter

    I was having issues where my syntax highlighting would contain <p> tags and <br> tags that weren’t really there. The reason seemed to be that Markdown was interpreting the code within the Syntax Highlighter code blocks, which is not what I wanted.

    To solve…

    In your Markdown text format, make sure the order has Syntax Highlighter above Markdown. In your Syntax Highlighter configuration set div as the Tag name setting. Markdown will ignore div tags and Syntax Highlighter will highlight them.

    Note that those are the only two filters I use in my Markdown text format. You may need to do more tweaking if you use more filters.

    Lastly, I actually prefer highlight.js, so I’ll probably be ditching Syntax Highlighter altogether… my blog is currently using both solutions. Excuse any messes if you see them; it’s in transition.

  • Development

    Free Shipping for Specific Products in Drupal Commerce

    Recently I had a client call me asking if she could offer free shipping on a specific promotional/limited-run product. Unfortunately I didn’t find any clear-cut solutions in contrib or Drupal Commerce core. Also, I could not come up with a way to do this in core through the Drupal admin UI. It’s very easy to allow a “Free” shipping method if a specific product is found in the cart/order, but we only wanted the “free” deal to apply to the single product (any quantity of it).

  • Development

    Maintaining Lightbox2 Templating

    Lightbox2 is a very popular and powerful Drupal module. One of the helpful features is that you can render a Drupal node in a lightbox rather easily in either PHP or HTML. View detailed explanation. The issue is that when you click a link within that lightboxed content, you will lose the lightbox2 templating (e.g., if your lightbox template hides sidebars, they’ll only be hidden when the node loads. If you click a link within the lightbox, the new node will load and sidebars will appear). Read on for a quick fix.