Doesn't work with CCK fields?

Adam_M - November 16, 2007 - 12:03
Project:Default Filter
Version:5.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

With Default Filter installed and working well for all page types, I notice that CCK fields aren't inheriting the default filter for the page.

Any ideas?

#1

jari - January 9, 2008 - 13:45

Yep, noticed this too.. We're moving from 4.7 to 5 or 6 and I've been waiting for a way to set the default input type per user group, since we don't want the visitors to use BBCode on comments but editors should have that as default.

Long story short - tried the module and while it works great for the body field, we definitely needed it to work with CCK fields as well.

I checked how the module works and wrote a few lines more to my existing custom module, so the code below only works for hard coded fields and doesn't have any fancy menus, but it might give someone help in implementing this feature if they need it really bad, too.

<?php
//Function for setting the default input format based on logged user's group
function mymodule_set_input_format($form, $format_id, $field)
{
    global
$user;
   
   
//A bit different code depending on if the field is body or some CCK-based
    //Set default for editors to BBCode
   
if(in_array(3, array_keys($user->roles)))
        (
$field == 'body') ? $form['body_filter']['format'][$format_id]['#default_value'] = 4 : $form[$field][0]['format'][$format_id]['#default_value'] = 4;
   
//Set default for admins to PHP Code
   
elseif($user->uid == 1 OR in_array(4, array_keys($user->roles)))
        (
$field == 'body') ? $form['body_filter']['format'][$format_id]['#default_value'] = 2 : $form[$field][0]['format'][$format_id]['#default_value'] = 2;
   
    return
$form;
}

//Alter the forms
function mymodule_form_alter($form_id, &$form)
{
    global
$user;
    if(
$form['#id'] == 'node-form')
    {
       
//If not editing the node, set the default input formats based on the user group
       
if(arg(2) != 'edit')
        {
           
//Set the default input formats for teaser field
           
if(isset($form['field_teaser']))
            {
                foreach(
$form['field_teaser'][0]['format'] AS $key => $value)
                {
                   
//Edit the default value for every format type
                   
if(is_int($key) AND isset($form['field_teaser'][0]['format'][$key]['#default_value']))
                       
$form = mymodule_set_input_format($form, $key, 'field_teaser');
                }
            }
           
//Set the default input formats for body field
           
foreach($form['body_filter']['format'] AS $key => $value)
            {
               
//Edit the default value for every format type
               
if(is_int($key) AND isset($form['body_filter']['format'][$key]['#default_value']))
                   
$form = mymodule_set_input_format($form, $key, 'body');
            }
        }
    }
}
?>

#2

andre_ - January 11, 2008 - 14:09
Category:support request» bug report

I have the same problem.

Andre

#3

trevorleenc - February 10, 2008 - 14:40

glad I just found this post...as I've already spent a little over an hour trying to figure out why in the heck this was not working...

hopefully a fix will come soon

#4

budda - April 28, 2008 - 14:04

Ditto. This problem is a little annoying.

#5

grendzy - August 22, 2008 - 21:40
Status:active» needs review

Here's a patch against the D6 branch.

AttachmentSize
default_filter_cck.patch 1.11 KB
 
 

Drupal is a registered trademark of Dries Buytaert.