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?

CommentFileSizeAuthor
#5 default_filter_cck.patch1.11 KBgrendzy

Comments

tormu’s picture

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.

//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');
			}
		}
	}
}
beauregard’s picture

Category: support » bug

I have the same problem.

Andre

trevorleenc’s picture

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

budda’s picture

Ditto. This problem is a little annoying.

grendzy’s picture

Status: Active » Needs review
StatusFileSize
new1.11 KB

Here's a patch against the D6 branch.