Getting a Drupal 6 WYSIWYG editor + IMCE + CCK field 'Add more' to party

It seemed like a straightforward feature: to create a CCK field with unlimited values, editable using a WYSIWYS editor including image uploads into the editor. The solution is actually trickier because out of the many possible combinations and settings for getting a WYSIWYG editor and file uploading to work, only this combo seems to work, across browsers (including Google Chrome):

The main problem seems to be the in whether the module implemented Drupal behaviours (correctly, or at all).

Anyway, tried these, and none of them worked for what we needed:

  • FCKEditor module 6.x-1.3: doesn't work with unlimited value fields - removes all editor instances when adding new values!
  • FCKeditor module 6.x-2.0-beta1: doesn't remove the editor from other fields but new 'add another item' value does not appear with the editor instantiated.
  • FCKEditor with Wysiwyg API: can't seem to enable file upload.
  • YUI RTE + YUI modules: doesn't work with unlimited value fields.

Filed under  //  cck   drupal   wysiwyg  
Posted by Farez Rahman 

Drupal: Use long CCK field labels

If you use CCK for creating Drupal nodes, you will find that there is an inherent 128 char limit for the field labels. This limit is due to the database column size so tough luck in trying to change this limit. If you absolutely must use labels longer than 128 char, like for questionnaires, here's a workaround which lets you use the feld description text as the label (the contents of this description text is usually shown as smaller greyed-out text under the field).

The disadvantage of this is you will not be able to show help description under the field, but this is only for the fields that you want longer labels on... fields with shorter labels can still show descriptions.

I've implemented this as a module called desc_as_label. When you need to have a field label longer than 128 chars, just use a field label prefixed with an underscore - this will not be shown to the user as the underscore is just to tell the module to use the description as the field label. Then type in the actual long label text into the field description field.

The code for the .info and .module files are shown below. Save them into a sites/all/desc_as_label and enable it in your site's Modules section.

As always, comments welcome!

File desc_as_module.info:

; $Id$name = "Description as Label"description = "Use the longer descriptive help text in CCK fields as the actual label."core = 6.xpackage = CCKdependencies[] = contentversion = VERSION

File desc_as_label.module:

<?php// $Id$/** * @file * Allow the use of the long 'help text' description to be used as the field label when * long labels are needed. Prefix the field title with an underscore and the help * text will be used instead. If help text is used, the help text will not be repeated * below the field. * * @version         $Revision$ * @modifiedby      $LastChangedBy$ * @lastmodified    $Date$ *//** * Implementation of hook_form_alter(). */function desc_as_label_form_alter(&$form, $form_state, $form_id){  if (in_array($form_id, array('_content_admin_field', 'content_admin_field_main'))) { _desc_as_label_admin_instructions($form);  } else { _desc_as_label_process($form);  }}/** * Amend the label to use the description, if the label has a leading underscore. * @param &$form The form to be modified, as passed into hook_form_alter(). */function _desc_as_label_process(&$form){  foreach ($form as $element_name => $element_array)  {    if (strpos($element_name, 'group_') === 0) {      _desc_as_label_process($form[$element_name]);    }    elseif (strpos($element_name, 'field_') === 0) {      if (strpos($element_array['#title'], '_') === 0) {       $form[$element_name]['#title'] = $form[$element_name]['#description'];       $form[$element_name]['#description'] = '';      }    }  }}/** * Show instructions for field admin form * @param &$form The form to be modified, as passed into hook_form_alter(). */function _desc_as_label_admin_instructions(&$form){  $form['new']['label']['#description'] = $form['new']['label']['#description'].' '.t('Maximum 128 characters. If you want a longer field name, you can use field Help description text as the field name instead. To do this, prefix this field name with an underscore, e.g. _longquestion, and then put the actual label to use in the Help description field.');}

Filed under  //  cck   drupal  
Posted by Farez Rahman