Hi!

I can't find any settings to set text format (FullHTML or FilteredHTML) by default for my custom content type. Please tell me, where to look for this setting?

Thanks.

Comments

Ricmar’s picture

If you go to structure > content types > choose 'manage field' of the content type you want and select edit you should see it as a radio list.

sun-fire’s picture

I see five positions at this list:

*Hide submission form settings
*Show publishing options
*Show display settings
*Show comment settings
*Show menu settings

I checked each tab in this list but I had not find any settings for text formats.

Ricmar’s picture

Create your content type first. Then go back in to where I listed above. I guess it can not be set immediately when creating a content type. But you can edit these settings on the 'article' and 'basic page' content types so should be able to on another custom content type.

PMorris’s picture

Took me forever to find this. You set the default text format by the field now: So go to your existing content type Structure > Content Types

Click manage fields beside the content type you want to edit. This includes default content types for drupal 7.

Click edit beside whatever field you want to change the default text format for. (This includes the Body text area like in Drupal 6.)

PMorris’s picture

So now I'm confused again. It's not saving the default for the field. When creating content the content type seems to default back to the first format available to a user. (like it says on the Text formats configuration page)

toastyghost’s picture

STILL broken in May 2012.

Scott M. Sanders’s picture

This need fixed.

stewartmiddleton’s picture

[EDIT] - sorry, I thought I had a solution, but I was wrong.

+1 that this is broken and does not save the value set for default text format :(

giupenni’s picture

Not work. I change text format but not save the new choose.

...!

syf70’s picture

It took me a while to figure this one out...

For EXISTING nodes, edit, select format and save. The editor will default to the last selected format from this point on.

For every NEW Nodes (default),
Configuration > Content Authoring > Text Formats
DRAG the desired default format to the top of the list.
Save

aangel’s picture

It wasn't obvious but wasn't hidden either, thanks for pointing it out.

André Angelantoni
Founder, PerformantLabs.com

ahimsauzi’s picture

Where is voting when you need one! Thanks Tricky, worked like a charm.

Steve Miller’s picture

Sorry, I'm not following this solution. For existing nodes, I'm not seeing anywhere to "select format."

mennonot’s picture

Thanks for these instructions on how to set the default "input format". This seems like an obvious piece of documentation to put in the help text for Configuration > Content Authoring > Text Formats. Anyone have any idea why it isn't there? Is it considered so intuitive that it goes without saying?

jeff.hines’s picture

This is the answer I was looking for.

seancr’s picture

This is a work around, not a fix. The defaults still are not saved and used when editing the content type.

vandanasom.123’s picture

Thank you :)

TWD’s picture

Brilliant. Thank you.

It says:
"Text formats are presented on content editing pages in the order defined on this page. The first format available to a user will be selected by default."

By default the order of text formats is

- Plain Text
- Filtered HTML
- Full HTML

so I guess most people will want to invert the order to

- Full HTML
- Filtered HTML
- Plain Text

gebhart_m’s picture

Thanks so much! This worked perfectly.

-Michelle

vabue’s picture

But is it possible to limit certain field to use special text format?

The only thing I see editing textarea field properties:

Text processing:

  • Plain text
  • Filtered text (user selects text format)
pembertona’s picture

You might want to check out the Better Formats module: http://drupal.org/project/better_formats which should have a full D7 release soon.

unc0nnected’s picture

Yup, better formats did the trick for me, just had to go into Better Format settings and enable the "Control formats per node type" option, then head into the content type and set that up

Check my blog for tons of Drupal, linux and webserver solutions

Jean Gionet’s picture

I'm currently manually importing some nodes from a drupal 6 install to a fresh drupal 7 install using Views Bulk Operations (VBO).
My problem is the format type is missing. Is there a way to mass update all the content (and it's revisions) to one of my new text formats? (like full_html for example)

thanks

A Day In The Life

philip-iii’s picture

Probably the easiest way to go about it is to manipulate the SQL tables directly. I was facing a similar challenge, and after fiddling about with the settings, figured a quick SQL query would do the trick just fine and save quite some time in the process. No idea if it does result in some side effects tho, use with caution and do backups in advance (although it is just as easy to revert to the previous value, rather than figuring out what obscure_module_x just broke and trying to fix that). Better suggestions are certainly welcome and I'd be eager to figure a simpler and easier approach (which does not include a terrible lot of clicking about and does not get in the way more than necessary).

Gerben Zaagsma’s picture

Could you perhaps explain how you did this in the database? I need to mass update imported nodes to full html as well. If I know the steps happy to do it in the db directly.

pfrenssen’s picture

I needed to change the default text format for a specific field in a custom content type. I have looked at how it is done in the Better Formats module.

The following code changes the default text format of a specific field in a specific content type:

  • Content type machine name: 'job'
  • Field machine name: 'field_company_spotlight'
  • Text format machine name: 'media_html'
<?php
/**
 * Implements hook_element_info_alter().
 *
 * Sets the text format processor to a custom callback function.
 * This code is taken from the Better Formats module.
 */
function MODULENAME_element_info_alter(&$type) {
  if (isset(
$type['text_format']['#process'])) {
    foreach (
$type['text_format']['#process'] as &$callback) {
      if (
$callback === 'filter_process_format') {
       
$callback = 'MODULENAME_filter_process_format';
      }
    }
  }
}

/**
 * Callback for MODULENAME_element_info_alter().
 */
function MODULENAME_filter_process_format($element) {
 
$element = filter_process_format($element);
 
// Change the default text format of the 'field_company_spotlight' field to
  // 'Media HTML'.
 
if ($element['#bundle'] == 'company' && $element['#field_name'] == 'field_company_spotlight') {
   
$element['format']['format']['#default_value'] = 'media_html';
  }
  return
$element;
}
?>
BeaPower’s picture

where do you put this?

pfrenssen’s picture

This needs to be put in a custom module. You can find information about how to create one in the Creating D7 modules tutorial.

geerlingguy’s picture

Perfect! Saved me a few hours' work looking up how Default Formats works.

__________________
Work: Midwestern Mac, LLC | Personal: jeffgeerling.com

yan’s picture

Thanks for that snippet. I used this modified version to set the default format for comment body fields to Filtered HTML (in Drupal 7):

<?php
/**
* Implements hook_element_info_alter().
*
* Sets the text format processor to a custom callback function.
* This code is taken from the Better Formats module.
*/

function MODULENAME_element_info_alter(&$type) {

  if (isset(
$type['text_format']['#process'])) {
    foreach (
$type['text_format']['#process'] as &$callback) {
      if (
$callback === 'filter_process_format') {
       
$callback = 'MODULENAME_filter_process_format';
      }
    }
  }

}

/**
* Callback for MODULENAME_element_info_alter().
*/

function MODULENAME_filter_process_format($element) {

 
$element = filter_process_format($element);

 
// Change input format to "Filtered HTML" for comment fields
 
if ($element['#field_name'] == 'comment_body') {
   
$element['format']['format']['#default_value'] = '1';
  }

  return
$element;

}
?>
drasgardian’s picture

I have multiple input formats and different ckeditor profiles for each input format.

I found that with that snippet, the input format for the field was changed correctly but ckeditor still loaded the incorrect profile.

I used this to override both the field input format and the profile loaded by ckeditor for a specific field.

/**
* Implements hook_element_info_alter().
*
*/
function MODULENAME_element_info_alter(&$type) {

  // add a pre_render callback of our own
  if (isset($type['text_format'])) {
    $type['text_format']['#pre_render'][] = 'MODULENAME_prerender_text_format';  
  }
}

/**
* pre render callback for MODULENAME_element_info_alter().
*/
function MODULENAME_prerender_text_format($element) {
  if (isset($element['#entity_type']) && $element['#entity_type'] == 'node' && $element['#field_name'] == 'FIELD_NAME') {
    // override the default input format
    $element['format']['format']['#value'] = 'email_safe'; // CHANGE THIS TO DESIRED INPUT FORMAT
    $element['#format'] = 'email_safe'; // CHANGE THIS TO DESIRED INPUT FORMAT. ckeditor will use this to display the correct profile
  }
 
  return $element;
 
}

pverrier’s picture

Thanks a lot, it helped me!
I did it another way (with hook_form_FORM_ID_alter - common process for all comment bodies), maybe it could be useful to post it there...

function MYMODULE_form_comment_form_alter(&$form, &$form_state) {
  $form['comment_body']['#after_build'][] = 'MYMODULE_form_comment_form_alter__only_plain_text_format';
}
function MYMODULE_form_comment_form_alter__only_plain_text_format($form) {
  global $user;
  if (!user_access('administer') && !in_array('La Redaction', $user->roles)) {
    // (except for Admin and certain roles) remove unauthorized filter formats for other users
    $elt = &$form[$form['#language']][0];
    $default = 'plain_text';  // filter to set by default
    $authorized = array($default);  // list of authorized filter formats ('filtered_html', 'full_html', and custom ones...)
    $options = &$elt['format']['format']['#options'];
    foreach( array_keys($options) as $filter )
      if (!in_array($filter,$authorized))  unset($options[$filter]);
    $elt['format']['format']['#value'] = $default;
    $elt['#format'] = $default;
  }
  return $form;
}

I was also inspired by http://technonaturalist.net/blog/2011/08/drupal-7-notes-unsetting-format...

Luukyb’s picture

This one didn't worked for me with CKEditor

I used a similar technique but with $element['format']['format']

<?php
/**
* Implements hook_element_info_alter().
*
* Sets the text format processor to a custom callback function.
* This code is taken from the Better Formats module.
*/
function MODULE_element_info_alter(&$type) {
 
// add a pre_render callback of our own
 
if (isset($type['text_format'])) {
   
$type['text_format']['#pre_render'][] = 'MODULE_prerender_text_format';  
  }
}

/**
* Callback for MODULE_element_info_alter().
*/
function MODULE_prerender_text_format($element) {
  if (isset(
$element['#entity_type']) && $element['#entity_type'] == 'node') {
    switch (
$element['#bundle']) {
      case
'techniques':
        if (
$element['#field_name'] == 'body' && isset($element['format']['format'])) {
         
$element['format']['format']['#options'] = array(
             
'techniques_method' => 'Techniques method',
             
'plain_text' => 'Plain text'
           
);
        }
        break;
      case
'recipe':
        if (
$element['#field_name'] == 'body' && isset($element['format']['format'])) {
         
$element['format']['format']['#options'] = array(
             
'recipe_method' => 'Recipe Method',
             
'plain_text' => 'Plain text'
           
);
        }
        break;
      default:
       
// Your default case, if needed ...
       
break;
    }
  }
  return
$element;
}
?>
Zaylril’s picture

If you want do just do this for a particular field you can do the following:

$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'filtered_html';

Took me a while to find this out, and also save you from having to edit this in the options menu if you don't want it site wide.

Hope this helps someone!

boshtian’s picture

Thank you for this solution. It works with no problem. Just change content type name, field name and format name.

You only have a little mistake that could be confusing. Before the code, you wrote that the content type machine name is job but in the code itself, the bundle is company.

pfrenssen’s picture

Thanks for letting me know! I will fix it in my original post.

edit: strangely enough I cannot edit that post, even though I can edit all my other posts on this page.

Omkara’s picture

Thank You! Just what I needed :)

joedag32’s picture

In Drupal 7 go to Configuration > Text formats

Then you can drag and drop the order of the text formats available and Save changes. They'll appear in that order with the top most by default.

sahaj’s picture

This works as general default value, but not as default value per Content Type.

.sahaj

bootn’s picture

Thank you so much for taking the time to post! Such a simple solution, that wasnt so obvious, saved me alot of time and frustration by posting your solution.

threadsniper’s picture

This solved a problem I was having as well. What's a simple and effective way of adding a field to this (I tried the OR operator, but this defaulted every field to the declared text format)?

jenlampton’s picture