Dates are always wrapped in a <time> HTML tag in a Views "REST Export" display

Created on 2 February 2024, 11 months ago
Updated 14 August 2024, 5 months ago

Problem/Motivation

I need to set a custom "Date format" for a field in a "REST export" display in a view.

Steps to reproduce

  1. Create a view with a "REST export" display.
  2. Use "Show: Fields"
  3. Add a date field, like "Content: changed"
  4. Configure the field with "Date Format: Custom" and any "Custom date format"
  5. Preview the view. Observe that the custom date format is wrapped in an unwanted HTML time tag.

Or you can simply import the exported views config I have attached.

Proposed resolution

The "REST export" display should not wrap field values in HTML tags.

Also, when using the "U" date format, I would expect the output to be an integer rather than a string.

Merge request link

None yet.

Remaining tasks

TODO

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

TODO

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Views 

Last updated 15 minutes ago

Created by

🇿🇦South Africa rudolfbyker South Africa

Live updates comments and jobs are added and updated live.
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.

  • Issue created by @rudolfbyker
  • 🇮🇳India Akhil Babu Chengannur

    Thanks for the detailed issue decsription. I tried to recreate this issue wirh the given view configuration in Drupal 10.2.2 & Drupal 11 versions and these are the observations.

    If custom date format is selected and 'U' is given as the format, Timestamp value of the date appeares correctly in the response.
    If another custom date format is used (Eg: m/d/Y), date gets correctly formated in the response.

  • 🇳🇱Netherlands Lendude Amsterdam
  • 🇿🇦South Africa rudolfbyker South Africa

    @Lendude those issues look similar, indeed, but they are marked as fixed, while I can still reproduce this issue by importing the attached `views.view.test.yml` file into a fresh Drupal 10.3.2 instance.

    @akhil babu you are correct. With the latest Drupal version, the "Date format" is respected, but the whole thing is still wrapped in HTML. I'll update the title and description of this issue.

    Partial workaround: Enable "Strip HTML tags" and "Remove whitespace" under "Rewrite results" when configuring the views field. The only problem is that it's still a string instead of an int when using "U" as the "Date format".

  • 🇿🇦South Africa rudolfbyker South Africa
Production build 0.71.5 2024