We don't currently discriminate between Null and empty with respect to fields and default values.

Currently:
When you add a field to a bundle NULL is populated to the DB and when you edit or view that content the default value is not displayed or prefilled into the edit form.

Steps to reproduce:

  1. Install Drupal
  2. Create some article nodes
  3. Add a boolean field to the article content type for 'Hide from home page'
  4. Edit the home page view and add a filter for 'Hide from home page is not equal to TRUE or is equal to FALSE'
  5. See the view is empty, even though there are two nodes without this field checked (the value is empty, because the field did not exist when the nodes were created
  6. Save one of the nodes and see it now appears

Proposed solution:
Use NULL to store default value and "" to store empty values. This allows us to inject the default value from the field definition on field_view_field(). If you take a step back it is exactly what a user would expect when defining a new field. It is also very beneficial to downstream modules like token and views.

CommentFileSizeAuthor
#1 Screenshot at 2012-02-23 12:19:33.png23.46 KBrogical

Comments

rogical’s picture

Status: Active » Postponed (maintainer needs more info)
StatusFileSize
new23.46 KB

Can you give some screenshots?
I'm not sure if you're talking about this.
dd

Draven_Caine’s picture

No, i mean add any field to panels, that has a default value. The default value is added in the fields API at /admin/structure/content-types/...

If the default value is suppose to show, it doesn't. It doesn't even render. So default value = no rendering

Draven_Caine’s picture

Status: Postponed (maintainer needs more info) » Active

As always forget to change the status /sigh

merlinofchaos’s picture

Panels is using core's render method.

Does this default value appear on the node?

Is the default value added after the node is created? Default values are not retroactive, for example.

Draven_Caine’s picture

the default value works int he node and in views. Its from a new node. Now what i am meaning is if you use %node:picture (or whatever field) not pulling the field itself, if you get my meaning there. its the "context words" i think they are the % placeholders.

merlinofchaos’s picture

Those are handled by token.module and passed through into CTools' keyword system. I'm afraid I have no control over what they actually output.

Draven_Caine’s picture

Project: Panels » Token
Version: 7.x-3.0-alpha3 » 7.x-1.0-rc1
Component: API » Code

Tossing it over to tokens than.

dave reid’s picture

Status: Active » Postponed (maintainer needs more info)

I have no idea what the actual bug is here, sorry.

Draven_Caine’s picture

Status: Postponed (maintainer needs more info) » Active

In panels there are "contextual keywords" for example %node:picture.

Now in this sense if i use a contextual keyword to grab the field value of %node:picture and the field has a value the it shows, but if the field is empty, the field does not fall back on the default value as specified in your field settings (use to be cck).

michaelfavia’s picture

@Draven: Earl, Dave and i spoke about this in irc and the conclusion is a little jargony but useful.

In short what you are expecting is totally understandable and we (im roughly speaking for them only in so far as we seemed to agree) think it is probably the way things should work. Unfortunately they don't work this way, but for good reason that is embedded in cores field api.

The long description:

  1. Fields are things you attach to bundles that hold attributes of your content. (e.g. text field, image)
  2. Bundles are types of entities useful for differentiating purposes. (e.g. basic page, article)
  3. Entities are what youre use to thinking of as content (nodes, users, terms, media)

When rendering tokens, the token module just calls field_view_field() on the field you've requested to get the token value.
By default drupal stores NULL as that fields its value on every piece of content when you created the field. Drupal interprets that NULL as empty when viewing or editing so nothing displays.

This can be confirmed by adding a field to an existing bundle (content type) and then editing/viewing the a node of the content type in question. You'll notice the default value is neither displayed nor added to the default value for the form.

In fact, the ONLY time the default value comes into play is in populating the entity creation form (node, term, user). In that case the formstate is populated appropriately and rendered with the defaults in there as you and I would expect.

In my opinion this is a bug. We should store "" on purposefully emptied fields and NULL on undefined (aka default) fields. If we did that we could very easily populate the "default value" from the fields definition when it is rendered by field_api and NULL comes up as its value.

The consequences of this are all beneficial.

When you add a field to an existing bundle (content type) all of the cotnent of that bundle gets the default value which most of the time will be empty. When you want a specifically empty field you just delete the default value out of the populated form item and save. The null will turn into a "" and drupal will know you dont want anything there.

Id also like to extend this to the imagefield so that it can benefit from the non exclusive nature of "default value and "empty". Ill try and make a case and a patch if i have time this weekend.

In the end every field should have a default value that is used if nothing has ever been specified for that content when it is rendered. And that default value should be able to be overridden with something or nothing as the user desires. If this is fixed upstream token can just keep doing its thing. Views might need a little love to make it work on filter and sort though says earl.

michaelfavia’s picture

Project: Token » Drupal core
Version: 7.x-1.0-rc1 » 8.x-dev
Component: Code » field system

Moving to field api. Id like to ask yched if he knows why things aren't this way before i get hacking down an alley that's been down before.

michaelfavia’s picture

Issue summary: View changes

Update to the real issue.

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.

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.

martijn de wit’s picture

Version: 8.6.x-dev » 8.9.x-dev
Issue summary: View changes

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pameeela’s picture

Title: Default Values » Differentiate NULL and empty for default values
Issue summary: View changes
Issue tags: +Bug Smash Initiative

This drives me nuts but I never thought to log it as a bug! I've updated the issue summary with steps to reproduce.

pameeela’s picture

Issue summary: View changes
quietone’s picture

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.