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 :(

NicholasS’s picture

Seems you have to select the Text_Format you want AND save something into the text field in order for it to save your default Text_Format preference. Probably a bug.

CProfessionals’s picture

NicholasS's  workaround helps! I am on Drupal 8 and the issue persists. After years of returning to this issue, I saw the solution above and can verify it solves the issue (kind of). Thanks again for posting this. So simple. I am surprised a module has not been released for this. I might have to write one. Stay Tuned.

randell’s picture

Changing the default text format and saving the Default value field with something (e.g. a space) works.

Morten-H’s picture

Seems to be the same problem for Drupal 8.

Only way to change the default text format is to change it, then add a space, then save. Otherwise it just goes back to the 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.

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.

yorsh’s picture

Wow, the right answer

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

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'
/**
 * 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.

__________________
Personal site: www.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):


/**
* 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 :)

mcdoolz’s picture

Thanks for this <3

-
Be the occasion.

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

commonpike’s picture

This thread has been going in all directions :-) The question was

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?

The answer is, when you created your content type and added fields, it's under 'edit field' of the text field where you want to set the text format. For me its right below the editor box (or the textarea) containing the default value. There are also sitewide defaults, but that was not the question.

The problem is, it doesn't work. https://www.drupal.org/node/1003262#comment-9725843 points out the bug report with a patch.

The good news is, it does work if you also enter a default value for your field. What I do for now is enter a comment as default value, which happens to be allowed in the text format I use for that field.

*-pike

jeffglenn’s picture

The comment above works, thank you.

While having a "default value" is not ideal it does let you save the text format as whatever you would like.

maxplus’s picture

Thanks,
setting a default value indeed saves the text format setting, good quick work around

RAWDESK’s picture

Hi Max,
There's a better option, see below...
Everything okay with you ? It's been a while. Greetings

RAWDESK’s picture

You have to go to admin/config/content/formats an reorder the listed text formats.
The one on top will be the default for all content type text fields with format filter enabled.

rcr1000’s picture

When I try this, the page does not let me drag the formats around. It has the four-arrowed drag icon when I hover over it, but when I click and drag, they don't go anywhere.

RAWDESK’s picture

Which Drupal version and browser are you on ?
https://www.drupal.org/node/2833779

butterwise’s picture

Much of this thread speaks to how to change the order of one's text formats, but this does not seem to answer the original question: changing the text format per content type - for example, use 'full text' as the default for one content type, 'filtered text' for another, and some other custom format for yet another.

When modifying or adding a field, one can change the format via the 'Text format' drop down, but as noted above this does not 'take' and the field will use the default format as defined by the global text formats configuration (/admin/config/content/formats).

However, if you change the formatting for your field *and* enter sample text in the field (e.g. 'Enter the caption here') as the default value, then the selected text formatting is preserved for each new node created using that content type (NicholasS observed above).

A minor nuisance for an editor, and it does not prevent an editor from changing the format (assuming their permissions allow this), but it does prevent the need for a module like Better Formats, which clearly states is not production-tested.

mimran’s picture

In Drupal 8 you can change the default text format as follow

$form['field_post_text']['widget'][0]['#format'] = 'plain_text';
glynster’s picture

This is what we do:

  1. Switch to the filter format you want, in our case it is the editor.
  2. Once editor is present switch to source.
  3. Then paste in a non-breaking space (&nbsp;)
  4. Then hit save.

Work a treat and will work per field as needed.

bsarchive’s picture

But this means there's always a space as the default field value, which is not so good if you have a non-required field or, as in my case, a non-empty field value will be interpreted and rendered as a link.

gardenChamber’s picture

По голове бил за _format как же это криво все