When creating content, I would like to have the input format for the Page node-type default to Filtered HTML AND
the Story node-type default to Full HTML.

I cannot locate any obvious swicthes from the admin->settings. Is this at all possible ?

Comments

rstoeber’s picture

I'm trying to do the same. Anyone know if this is possible?

The Filter module description makes it sound like that's the way to do it, but I can't see how/where.

stephthegeek’s picture

Ditto. I'm using freelinking and a flexinode type to create a wiki and I'd like to default (or restrict) users when editing a wiki page to only be allowed to use the freelinking input format.

sofyst’s picture

I am using TinyMCE for a WYSIWYG editor, and if 'full html' is not selected then line breaks do not appear in my comments or post (ANNOYING!).

So if anyone comes across this option, please share!

azharhafiz’s picture

it's 2010 and it's still haven't been figured out

irakli’s picture

Actually, it has been figured out: http://drupal.org/project/filterbynodetype

mazeem1234’s picture

I'm trying to do the same. Anyone know if this is possible?

The Filter module description makes it sound like that's the way to do it, but I can't see how/where.

Ford F Series Supercharger

sofyst’s picture

Ok, I figured it out. I don't know why I didn't see it before. The option is under administrator > input format. It is that simple.

bomarmonk’s picture

Is there a way to set different defaults for different node-types? Right now, the default on admin->input formats sets the default for all nodes, right?

catch’s picture

I'd be interested in this as well.

For example, it'd be great to be able to set bbcode for forum topics and comments, but rich text/tinymce for pages and stories.

This thread: http://drupal.org/node/35245

has a hack to associate input formats to content types, but I'm not sure if that'd work with 4.7

Is this something that could be incorporated into CCK? Ideally, in the same way default publishing options are set for node types, input format could be set there as well.

Anonymous’s picture

One way to achieve this is set the default to "Filtered HTML" and in any modules you want a different defaul format, in the _form hook, you'll find something like:

$form['body_filter']['filter'] = filter_form($node->format);

You can hardcode a module to always default to a specific format - in my case Full HTML is format 3 (did a printf to find this).

$form['body_filter']['filter'] = filter_form(3);

Users couldn't override it anymore, but in my case I don't want them to anyway.

bubuk.gabrok’s picture

Thanks, that work for me.

Antikx’s picture

This sounds exactly like what I want.
I would like users to always be using the default Input Format when in the forum, typing comments, etc. But when they are adding content in the Wiki (Liquid Wiki) I would like the only option to be the Wiki Input Type (an Input Type I manually created). Right now they have to change it from the default to Wiki when creating new content.
I admit I'm not knowledgeable enough to understand what gbear means.
#1 Am I supposed to enter the hardcoded body filter line into liquid.module file? Or where is the "_form hook"
#2 What is meant by "printf to find this"? I tried things like:

printf filter_form(4);

...but I'm not getting any results.

Thanks in advance!

Antikx’s picture

I looked into the hook_form some more: http://api.drupal.org/api/4.7/function/hook_form
I created this in the liquid.module file:

function hook_form() {
$form['body_filter']['filter'] = filter_form(4);
return $form;
}

Alas, it still doesn't seem to change the input filter. I am I on the right path? I'm I in the right file?

Antikx’s picture

I have a feeling my question is buried in this node. If anyone can answer it I would really appreciate it, cuz It's driving me nuts. Thanks.

reggie75’s picture

i think youre doing it wrong.

what the poster was trying to say is you need to make the changes in the module_form() function of your module.

eg: if your module is hello.module, then the function you need to touch is hello_form()

This function must be already there, and it is responsible for diaplying the input form of the module to your user.

Now in this function, you can specify what inpur fotmat you want as default:
by pasting the line thats mentioned in his post.

hth,
reggie

Antikx’s picture

Thank you, thank you, thank you.
I had to stumble around for a but longer, but I found the line in the liquid_wikipage.module instead of the liquid.module and after some trial and error about what number to put in I have it working perfectly. Ya!
Glad to have this issue past me. It will increase usability so much.
Thanks again!

reggie75’s picture

glad it worked :)

johntymatts’s picture

$form['body_filter']['filter'] = filter_form($node->format);

You can hardcode a module to always default to a specific format - in my case Full HTML is format 3 (did a printf to find this).

$form['body_filter']['filter'] = filter_form(3);

I am trying to do this, but when I edit the module file vote_storylink.module it simply does nothing, Except the administrators default input changes, however non administrators have no change to there input types.

I'm trying to edit vote_storylink.module from the vote up down so that it only accepts plain text, I created a plain text filter, then modified the module file as above but instead of changing to filter 3 I chose 4 I'm using 4.7 any ideas?

robotjox’s picture

Thanks a lot for this thread - I managed to change the default input format for my wiki by changing a line in the node.module to:

$form['body_filter']['format'] = filter_form(7);

However, I'm not sure this is the best way to do it, hacking a core module - so I guess my question is - is there a better way to do this - perhaps by adding some lines to my template.php?

thanks

stephencarr’s picture

Unfortunately this does not allow you to separate out the comments for their own formatting. I don't want the same kind of formatting available to a normal post and a comment.

niklp’s picture

Subscribing cos I've spent ages on this and found no solution.

Kineta Systems - Web Development in Nottingham

masterpiga’s picture

I did a rough porting of the filterbynodetype module to Drupal core 6.x.

I've also extended the module so that it also allows to select which input filters can be used with comments.

If you want to give it a try, you can download it from http://danielepighin.net/cms/software .

phpsharma’s picture

This is a great module for 5.X.X
http://drupal.org/project/filterbynodetype

sharma chelluri

truedat101’s picture

I needed this functionality to restrict node input filters for Wiki nocdes (limit to Twiki Wiki filter). Thanks, works great in 6.x!

"There's a module for it." - anonymous

kassissieh’s picture

I was able to accomplish what I wanted by a different method. I have just one content type where I want to use a different input format. I created a custom module and use the following hook to change the input format upon submission (before the form contents are sent to be processed and saved).


function your_custom_module_name_node_form_submit($form, &$form_state) {

  if ($form_state['values']['type'] == 'your_content_type') {

    // change to full html input format
    $form_state['values']['format'] = 2;

  }

}

mikii84’s picture

I tried all the solutions i have seen here. None of it seems to work. What might I have done wrong?

vizulefllry’s picture

You spammed the node with the stink of your spam link.

5t4rdu5t’s picture

If you want to change the default input format for the body field of a specific content type, using hook_form_alter:

<?php

function example_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'type1_node_form':
      // Set default body field input format to Filtered HTML
      foreach(element_children($form['body_field']['format']) as $key) {
        $form['body_field']['format'][$key]['#default_value'] = '1'; // Filtered HTML
      }
    break;
    case 'type2_node_form':
      // Set default body field input format to Full HTML
      foreach(element_children($form['body_field']['format']) as $key) {
        $form['body_field']['format'][$key]['#default_value'] = '2'; // Full HTML
      }
    break;
  }
}
?>

On my system values are 1 for Filtered HTML, 2 for Full HTML, 3 for Messaging plain text, 4 for PHP code and 5 for WYSIWYG. Yours may be different, try doing a

print_r($form['body_field']['format'])

to see your actual values.

tomas.teicher’s picture

I think,
for this function you can use module "Better Formats" .

Tomas

dunx’s picture

A bit late to the party, but what Tomas said. Install better_formats and one of the functions that provides is allowing different default entry types per role for each content type. You have to turn this on under the setting for better_formats and then go to the content type and configure it there.

terbs’s picture

Use hook_form_alter and an after_build function. Afterbuilds are a bit weird. Don't forget to return $form in the afterbuild, and make sure to take a look at the structure of the $form object, because it changes in the afterbuild function.

function mymodule_form_alter(&$form, &$form_state, $form_id){
  $form['#after_build'][] = "mymodule_after_build";
}

function mymodule_after_build($form, &$form_state){
  
  //Set the default input format to 5 for "my cck field" in the fieldset "my fieldset"
  $form['my_fieldset']['my_cck_field'][0]['format'][5]['#value'] = 5;
  
  //Don't forget to return, $form is not passed by reference here.
  return $form;
}

If you're doing this in conjunction with better formats, you'll need to use hook_elements instead. Make sure your module weight is higher than BF in the system table so your hook runs after

function mymodule_elements() {
  return array(
    'text_textfield' => array(
      '#process' => array('mymodule_text_process'),
    ),
    'text_textarea' => array(
      '#process' => array('mymodule_text_process'),
    ),
  );
}



function mymodule_text_process($element, $edit, $form_state, $form) {

	
	if($element['#field_name'] == "my_cck_field"){
		$field = $form['#field_info'][$element['#field_name']];

		if (!empty($field['text_processing'])) {
	    	// Get core default for new or selected format for existing.
	    	$filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
	    	$parents    = array_merge($element['#parents'] , array($filter_key));
	    	$default    = better_formats_get_default_format('node', $form['type']['#value']);
	
	    	//Force the default the format ID
	    	$format = 7;
	    
	    	$element['#value'][$filter_key] = $format;
	    	$element[$filter_key] = better_formats_filter_form($format, 7, 'node', $form['type']['#value'], 1, $parents);
	    }				 
	}
	
	return $element;
}


jenlampton’s picture