Bug:
1. Create input formats A and B. Make A the default (for everything).
2. Define a new CCK text field with "user selects input format" (for content type "page").
3. Save a default text for the CCK field, choosing input format B.
4. Go to the "create content" page (create page content). You will notice that the default text is there, but the input format is A instead of B.

Solution:
In better_formats_text_process(), the following lines need to change:

Old:

<?php
    // Overwrite format default if new node.
    if (!isset($form_state['values']['nid']) || !isset($format)) {
      $format = $default;
    }
?>

New:

<?php
    // Overwrite format default if new node, unless the field has a default text.
    if ((!isset($form_state['values']['nid']) && !isset($element['#default_value']['value'])) || !isset($format)) {
      $format = $default;
    }
?>

Comments

dragonwize’s picture

Status: Needs review » Postponed

I rarely use default text values so I was quite surprised at the side effect that this patch allowed to show through.

CCK now stores the default format even when the default text box is empty.

This has huge repercussions for BF's options, good ones. I don't know what version that happened in. I looked through the recent versions and didn't see a specific call out so I assume it is a side effect of something else that was changed. Either way that is good for us.

Technically, to fix the problem you describe here the patch needs to use:

empty($element['#default_value']['value'])

instead of

!isset($element['#default_value']['value'])

That would only overwrite the value if a value exists because CCK is always setting the value blank or not.

In light of all of this, I have started the 2.x branch and will be building it to have BF not set a default format on standard CCK text widgets at all. Instead we will let CCK handle it. For those that want to have the full power of BF options for the CCK field I am putting #350696: Per field format settings with full BF options via CCK widget in the 2.x branch.

I am still thinking about whether or not any of this patch will make it into the 1.x version. If it does it will be the empty() version not the !isset() version as that would drastically change how BF works which I am not going to do mid version.

donquixote’s picture

This makes a lot of sense!
The CCK default value won't help us with input format restrictions (field A can use TinyMCE and MediaWiki, field B can use FCKEditor and Markdown), but it does help with default formats.
I'm not sure if format restrictions by field are a typical use case, but it would make sense to have it for the sake of completeness. People install BF because they are not happy with the default choice.

[sidetrack:i18n]
As a side note, I noticed that creating a node translation does copy the text, but not the format. Which can be a problem, if a "filtered html" node text is copied into a field with wysiwyg or raw. This happened on a site with BF enabled (and I don't want to risk disabling it), so I thought maybe it is related.
[/sidetrack:i18n]

dragonwize’s picture

Status: Postponed » Fixed

I've committed this to 2.x and do not plan apply this in any version to the 1.x branch. Thank you for bringing this to my attention.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

donquixote’s picture

There is one little problem with this:
CCK will not save the format in "default value", if the text is an empty string.

I tried to work around this by setting the text to " " (which is != empty string). This works, but for the final form I would like to get rid of the space.
So, this is what I tried, inside better_formats_text_process():

<?php
    // Overwrite format default if new node.
    // using patch idea from http://drupal.org/node/720278#comment-2659250
    if ((!isset($form_state['values']['nid']) && empty($element['#default_value']['value'])) || empty($format)) {
      $format = $default;
    }
    if (is_string($element['#default_value']['value'])) {
      if (!strlen(trim($element['#default_value']['value']))) {
        if ($element['#value']['value'] == $element['#default_value']['value']) {
          // we assume the value is sitting here only so cck will save the default format.
          dpm(__FUNCTION__);
          $element['#value']['value'] = '';
          $element['#default_value']['value'] = '';
        }
      }
    }
?>

For some reason this does not work. The textarea in the node creation form still has a space.
Any idea why?

(this is still all on 1.x, btw)

donquixote’s picture

Btw, I currently cannot save any default text for textareas.