Problem/Motivation

If you create a new field with a default value on an existing content type, the value is not set for previously created nodes, even when the nodes are edited.

Original report by NancyDru

This was originally reported against a field provider (#1827444: Default value not saved), but appears to be a core Fields issue. I added a new field to an existing content type. It has a default value. It would be nice if existing nodes were updated, but I didn't really expect it. However, editing existing content still does not save the default value. This is not good.

Comments

pjcdawkins’s picture

Status: Active » Closed (works as designed)

Entity forms start off with default values for new entities. But when you're editing an existing entity, then form elements for fields & properties are populated with the existing values for that entity.

It appears to be documented well. When you edit a field, the "Default value" section has this description:

The default value for this field, used when creating new content.

So this is surely "works as designed" unless I've misunderstood the OP.

NancyDru’s picture

Status: Closed (works as designed) » Active

It may work as designed, but, IMHO, the design is flawed. If a node is edited and has no value for a field with a default value, then that default should be used, new node or not. This is the way most Forms API developers create forms.

swentel’s picture

Version: 7.17 » 8.x-dev

Also tempted to call it by design, or else rather a feature request than a bug. Needs to move to 8.x first

swentel’s picture

However, editing existing content still does not save the default value

Oh wait, that is definitely a bug - or at least relatively easy to fix.

(edit, although, still, maybe not a bug, I don't know, depends on expectations I guess)

NancyDru’s picture

Look at most Forms implementations, including many in core:

  '#default_value' => $current_value ? $current_value : $field_default,

Maybe it's a feature request; I don't care what it's called. It is a major annoyance the way it is now.

pjcdawkins’s picture

Well, the behaviour is clearly not a mistake, given the default-value-widget description I mentioned - "The default value for this field, used when creating new content". That sentence (in field_ui.admin.inc) appears to have been around since August 2009 according to git blame and it might even have been inherited from CCK.

Perhaps a D7 Field maintainer could explain why defaults only ever applied to creating new content - maybe contact @yched.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drugan’s picture

Issue summary: View changes

The example how it could be resolved is here:

#2816859: Allow the 'step' to be configured as a NumberWidget setting

It works on the number field exactly as suggested @NancyDru on #2.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Title: Default values not saved » Default values do not apply to previously created content even when edited
Issue summary: View changes
pameeela’s picture

Issue tags: +Bug Smash Initiative
catch’s picture

Status: Active » Closed (works as designed)

Moving this back to works as designed, if we implemented it as suggested, then even if you zeroed out a default value when you saved, it would be set back to the default next time you edited.