Problem/Motivation

Sometimes it is desirable to show unpublished content in lists, so admin users can preview things before publication. However, when the list is sorted on a node's publication date, unpublished nodes all have a publication date of zero and sink to the bottom. A more accurate depiction would be for unpublished nodes to appear at the top of the list, as if their publication date was the current time.

Proposed resolution

  • Change the default value for unpublished content from 0 to 2147483647 (the maximum value the database field can hold). That will make views sort properly.
  • In addition to the published_at node property, add a published_at_or_now node property that equals the REQUEST_TIME when no publication date has been set.

Remaining tasks

  1. Make sure this works.
  2. Commit it.

User interface changes

None anticipated.

API changes

When implementing hook_publication_date_alter(), if no publication date has been set then $published_at will equal the defined constant PUBLICATION_DATE_DEFAULT, instead of 0.

Data model changes

None anticipated.

Comments

jstoller’s picture

Assigned: Unassigned » jstoller
Status: Active » Needs review
StatusFileSize
new6 KB

First stab at a fix.

Status: Needs review » Needs work

The last submitted patch, 1: fix_sorting-2532576-1.patch, failed testing.

jstoller’s picture

Status: Needs work » Needs review
StatusFileSize
new6.01 KB

Fix test.

jstoller’s picture

StatusFileSize
new7.61 KB

Patch take two. Now with install function!

Status: Needs review » Needs work

The last submitted patch, 4: fix_sorting-2532576-4.patch, failed testing.

jstoller’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new9.52 KB

Cleaned up the patch a bit and hopefully fixed the test error. Also updated the issue summary to reflect the chosen approach.

jstoller’s picture

Anyone want to review and test this patch before I commit it? I don't think I broke anything, but...

  • jstoller committed bf29ddf on 7.x-2.x
    Issue #2532576 by jstoller: Fix sorting on publication date so...
jstoller’s picture

Status: Needs review » Fixed

Pushed to dev. Change record published at: https://www.drupal.org/node/2646240

Status: Fixed » Closed (fixed)

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