Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal Module of the Week: Values

Parent Feed: 

A while back, a client asked how they could add an item to a select list on one of their content types. At the time the options in the select list were managed by the allowed values field on the field settings form (using the key|value syntax). I definitely didn't want to give the client permissions to edit content types. So what do I do? Do I use taxonomy? I was actually specifically not using taxonomy in this case. I didn't need any of the extra overhead that comes along with it (term listing pages, fields, entity bloat etc). I just wanted a simple interface to manage sets of key value pairs. A quick google search and I found the Values module.

I recently became a co-maintainer on the values project and have been working on a D7 upgrade and release. I've fixed all the issues in the issue queue and just pushed a release candidate so I figure it's a good time to highlight the module. The following is specifically for the D7 version, but most of the stuff is the same in D6.

Values

At it's core, Values is an interface for managing reusable sets of key-value pairs. It also provides a light api for storing and retrieving value sets from the database. To get started go to admin/structure/values and click "Create a value set".

This will take you to the value set edit form. Enter a value set name (the machine name will be generated automatically) and a description (optional). Then start populating your values. The keys for the values will be generated automatically as well, but you can change them if you want.

Hit save and you're done. Your value set is saved and ready for use... but where are you going to use it?

Values Field

This submodule is what actually allows you to use your value sets as allowed values for any "List" type field. It's pretty straight forward to use. Just create your value set and then select it from the list on the field settings page:

Values Webform

Another submodule that adds support for Value sets to select components in webforms:

Features Support

Although it's not a requirement of the module, Values comes with ctools support to create exportable value sets. This means that you'll get Features support out of the box to push your value sets between your dev/stg/prod environments. You can also export indvidual value sets from the edit page by clicking the "Export" tab.

Importing

Exports made using the ctools method above can be imported (obviously), but there is another format you can use to import value sets. On the import page (admin/structure/values/import) you have the option of doing a ctools import or just a flat list of values. Keys will be generated automatically but if you want to specify them you can use the old key|value format. This can be useful if you have a large list of values in a text file that you just want to bulk import quickly.

Conclusion

And there you have it. A one stop shop to manage value sets in Drupal. Give it a try and hit up the issue queue if you need help, or if there's a feature you're looking for.

Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web