Module Monday: Field Multiple Limit

How to Set a Display Limit on Drupal's Multi-Value Fields

With the release of Drupal 7, the popular Content Construction Kit module is baked into Drupal core. Now called FieldAPI, it allows site builders to add custom data fields to content types, user accounts, comments, and more. It also supports Multi Value Fields -- add an image field to a "Gallery" content type, for example, and users can attach an unlimited number of images to each node.

Unfortunately, the awesome flexibility of unlimited multi-value fields can be a pain when it comes time to display content, especially in space-constrained teasers or listing pages. A user who attaches fifty images to their "Gallery" node can easily spam the front page with thumbnails, or even break carefully-designed layouts. Enter Field Multiple Limit, a handy module that lets you control just how many items in a multivalue field will appear when an entity is displayed.








Screenshot of administration screen

Once the module is installed, any multi-value fields will have an additional "How many values to display" option. Even Taxonomy Term fields that Drupal provides on the default Article content type can be controlled; if users are allowed to create their own taxonomy terms using free tagging, this prevents heavily-tagged articles from cluttering up the front page with dozens of tag links.

Because the display limits are implemented in a field formatter, you can set up different limits for each display mode an entity supports. For example, you might display five photos on a teaser, ten in an RSS feed, and unlimited photos in the full version of a node.








Multi-value fields with different display limits for full and teaser modes.

Field Multiple Limit is currently listed as an "Alpha" release, but its simplicity and stability make it worth checking out. It relies on Field Formatter Settings, a handy API that allows modules to add new features and settings to an existing field formatter; that module and its related projects are also a great way to quickly tweak the presentation of Drupal 7 fields. Give them a try!

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!