0

I want to add a checkbox-field to each image I upload (like the title- or alt-fields) , to set the option whether the theme should render the image as a gallery or not. the value should be saved in the db. int(1)

I don't want to install heavy modules for this...

edit: but if there is no other option, I take the module :D

is there maybe a strategy I should use to solve the problem? writing a widget or something? hooking into the images_schema ?

2
  • is every image a node or do you allow multiple images per node?
    – uwe
    Nov 5, 2011 at 16:47
  • multiple images. Nov 6, 2011 at 12:12

1 Answer 1

1

I just did this with the imagefield extended module and a small custom module. After enabling the imagefield_extended module, I add this code to my custom module.

/**
* Implementation of hook_imagefield_extended_widget().
*/

function MYMODULE_imagefield_extended_widget($element, $extra_values) {
  // If you need the field or widget to conditionally add a FAPI field, use these.
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $widget = $field['widget'];
if($element['#type_name'] == 'occupancy_status' && $element['#field_name'] == 'field_task_files'){
  return array(
    //This will Replace the Textfield with dropdown select for the description
    'description' => array(
      '#type' => 'select',
      '#title' => t('Document Description'),
      '#options' => array(
         'Occupancy Flyer' => t('Occupancy Flyer'),
         'Personal Property Release' => t('Personal Property Release'),
         'Introduction Letter' => t('Introduction Letter'),
         'Notice of Rights' => t('Notice of Rights'),
         'Miscellenous' => t('Miscellenous'),
      ),
      // this makes b the default value when the value is not set.
      '#default_value' => isset($extra_values['description']) ? $extra_values['description'] : 'Miscellenous',
    ),
  );
  }



   if( $element['#type_name'] == 'property_gallery' && $element['#field_name'] == 'field_gallery_images' && arg(1)!=='add'){


  return array(
    //These are stored in the 'data' column of the cck imagefield's db table
    'revised' => array(
      '#type' => 'checkbox',
      '#title' => t('Revise This Description'),
       '#default_value' => isset($extra_values['revised']) ? $extra_values['revised'] : 0,
     '#attributes'=>array('class' => 'revise-check')
       ),
    'revisedby' => array(
      '#type' => 'textfield',
      '#maxlength' => 64,
      '#title' => t('Revsied By'),
      '#description' => t('Replace your name with the current name if you are making a new revision.'),
     '#default_value' => ($extra_values['revised']==0) ?  NULL : $extra_values['revisedby'] ,
       ),
       'revisedon' => array(
      '#type' => 'date',
      '#title' => t('Date Revised'),
     '#default_value' => ($extra_values['revised']==0) ?  NULL : $extra_values['revisedon'] ,

       ),

  );
  }
} /*End function */

You have the ability to add or modify the filefield or the imagefield field widgets. The only problem that I'm stuck at is making this work for fupload_imagefield.

1
  • 2
    I am using d7... is there maybe a strategy I should use to solve the problem? Oct 6, 2011 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.