Default text formats are not saved properly without accompanying values

Created on 14 September 2011, about 13 years ago
Updated 14 November 2023, about 1 year ago

Problem/Motivation

When settings the default value for a "Text (formatted)" field (either as a textfield, textarea, or textarea with summary), if you only set the default format, the result is not saved. In order to save the default format, you must enter non-whitespace text in the default value field. This is a usability issue as site builders want to specify a given text format (and, thus, the WYSIWYG editor config or the lack of an editor altogether) for a field without entering default text.

Proposed resolution

Include the format value in \Drupal\text\Plugin\Field\FieldType\TextItemBase::isEmpty().

Remaining tasks

  1. Write tests.
  2. Write change record for TextItemBase::isEmpty

User interface changes

None. Other than the expected result of having your settings saved! :)

API changes

Classes that extend TextItemBase will need to consider the change to the isEmpty() method.

Data model changes

None.

Original report

I try to set a default text format to a field (Long text) but it's not saved if i don't set a default value for the field.

1. I edit the field
2. I set the Text processing to "Filtered text (user selects text format)"
3. I set "Text format" to a another text format
4. Then i save

If i also set a default value for my field, my text format is set as default
But if i leave the default value of my field, it's not saved.

The function "text_field_is_empty (field/modules/text/text.module - line 51-)" is called. This function check only the value for the field, not the format. It return true and the function "_field_filter_items (field/field.module - line 51-)" unset this item including my text format.

If i change the function function text_field_is_empty

function text_field_is_empty($item, $field) {
  if ((!isset($item['value']) || $item['value'] === '') && (!isset($item['format']) || $item['format'] === '')) {
    return !isset($item['summary']) || $item['summary'] === '';
  }
  return FALSE;
}

to

function text_field_is_empty($item, $field) {
  if (!isset($item['value']) || $item['value'] === '')) {
    return !isset($item['summary']) || $item['summary'] === '';
  }
  return FALSE;
}

my text format is set as default event i don't enter a default value for my field.

But i'm not sure it's the good way to fix this issue.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Text 

Last updated 15 days ago

Created by

🇫🇷France Raphael Apard

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024