Problem/Motivation

I found an error with token [node:published] used in Metatag, instead of empty string we have NULL.

Steps to reproduce

1. Enable Metatags module
2. Open settings for content and set [node:published] token to article-published-time field.
3. Start creating a new unpublished node
4. After saving you get 500 error on node page for any user.

Proposed resolution

Port solution from 7.x branch - https://git.drupalcode.org/project/publication_date/-/blob/7.x-2.x/publi...

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

twilderan created an issue. See original summary.

twilderan’s picture

Assigned: Unassigned » twilderan
Status: Active » Needs work

twilderan’s picture

Assigned: twilderan » Unassigned
Status: Needs work » Needs review

Added check for field value and return empty string for unpublished nodes. Solution from 7.x branch.

jessey’s picture

keshavv’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new416.42 KB
new76.08 KB

I am able to reproduce the issue with the given steps.
There is an issue and both patch and MR works well.
The published date field is a non-required field, If you create an unpublished node, The value of the field gone null which will encounter the error.
Adding Screenshots.

fago made their first commit to this issue’s fork.

fago’s picture

Title: Missing token value for unpublished nodes » Missing token value for unpublished nodes, exceptions for unsaved nodes
Version: 8.x-2.0-beta7 » 3.x-dev
Priority: Normal » Major
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new6.66 KB

I also ran into this or a similar issue, with autosave_form. In this case the token results in an invalid-argument-exception error!

I updated the branch, and added a kernel test to cover the cases. Note: I've used AI to help me with that.

Also attaching a patch file for usage with composer-patches.

mably changed the visibility of the branch 3347012-missing-token-value to hidden.

shraddha kandale’s picture

StatusFileSize
new1.44 KB

publication_date: 2.0.0-beta8
acquia_optimize: 2.0.0

Issue summary
While using Metatag tokens with unpublished (draft) content, I encountered an error when running Acquia Optimize Quick Scan.

Steps to reproduce

  • Enable the Metatag module.
  • In Metatag settings for content, set the [node:published] token to the article-published-time field.
  • Create a node, leave it unpublished (Draft), and save it.
  • Edit the same node and run Acquia Optimize Quick Scan.
  • The following errors occur:
    • 500 (Internal Server Error) on the node edit page
    • Exception: InvalidArgumentException: The timestamp must be numeric

Notes
I’ve added a patch that fixes both issues by handling the unpublished node case correctly. After applying the patch, the node edit page and Quick Scan work without errors.
publication-date-token-fix.patch