ImageField Extended

Alan D. - September 15, 2009 - 15:08

An extended ImageField widget that adds new form fields to a Image field. It provides no new theming functions, it just provides the framework to associate new data with an image.

All processing, including storage, is done via ImageField. This module simply allows you to easily extend the currently available form fields; alt, description, title, etc.

A very simple admin interface provides a way of adding textfields, textareas, WYSIWYG textareas and checkboxes. Once defined here, each new form field can be enabled on each widget seperately.

Of interest to developers will be a new hook "hook_imagefield_extended_widget" that provides a programmatic way of adding any FAPI elements to the ImageField data form element. This '#tree' element has all of its data automatically saved by the FileField field.

We currently are using this approach to reuse a single multiple value ImageField to preform multiple tasks. Using checkboxes, the image can be flagged as featured, weighting it up to be used as the teaser image based on this. Others can have a node header image flag added, marking it to insert as the page header, or gallery to hide / show in an inline imagefield gallery, etc. New fields such as Camera, Photographer, Copyright, etc can also be added, then custom theming can provide this information in the UI.

Usage

No programming

  1. Download, install and enable
  2. Go into your site configuration and find "ImageField Extended Fields" (http://www.example.com/admin/settings/imagefield-extended) and define one or more new form fields.
  3. Once you have defined the new form fields above:
    • you need to create a "File" field using a "Image, with additional fields" widget. The additional form fields that you have defined will be configurable per field type. All new additional fields are disabled by default.
    • You can also change the widget type from "Image" to "Image, with additional fields" for existing fields. Remember to enable the new form fields that you want.

Programming

Use the hook to return all of the new elements that you want to add into the ImageField widget. The submitted values are all stored within the serialized data element by FileField. An example can be found here.

Security note

The module does not present data itself, but you do. Here are the recommended ways to handle the text options.

Typical text field (no HTML)

<?php
$no_markup
= isset($data['no_markup']['body']) ? check_plain($data['no_markup']['body']) : NULL;
?>

Text field with tags (HTML)

<?php
# You can use filter_xss_admin for TRUSTED users.
$free_text = isset($data['free_text']['body']) ? filter_xss($data['free_text']['body']) : NULL;
?>

Rich text (WYSIWYG)

<?php
$rich_text
= '';
if (isset(
$data['rich_text']) && !empty($data['rich_text']['body'])) {
 
$rich_text = check_markup($data['rich_text']['body'], $data['rich_text']['format'], FALSE);
}
?>

Limited to ImageField 6.x-3.x branch only

Branch versions match the corresponding ImageField that they can be used against. Use the 6.x-3.x branch of this module against ImageField 6.x-3.x only. Using ImageField 6.x-1.x or 6.x-2.x will not work.

Do you have some code examples to share? Help document the module here.

Sponsorship

Module sponsored by Caign Webs.

Releases

Official releasesDateSizeLinksStatus
6.x-3.12009-Oct-059.63 KBRecommended for 6.xThis is currently the recommended release for 6.x.
Development snapshotsDateSizeLinksStatus
6.x-3.x-dev2009-Oct-179.92 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.