- Issue created by @swirt
- πΊπΈUnited States swirt Florida
This does result in a secondary warning
Deprecated function: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\dkan_rss\DkanRssCreator->dateSort() (line 287 of modules/contrib/dkan_rss/src/DkanRssCreator.php).
but that is just the result of having no pubDate
- π©πͺGermany stefan.korn Jossgrund
Thanks for pointing this out.
Since the pubDate is defined by a property of the dataset (issued by default) and this property is not necessarily required, it is possible that pubDate is empty. pubDate is also not a required property of an RSS feed. So there should be handling there in case pubDate is empty.
Question is how to handle an empty pubDate while sorting by date. The php DateTime is using "now" as default. So we could go with that as a default as well. But that seems not suitable, because the sort would change dynamically in time.
So I think, putting a dataset with empty pubDate at the end of the feed, is probably the best option.
That said, you can also arrange a different sort (or no sort) if you change the schema json. Removing the "_sort" part altogether would apply no sorting. In that case the sorting is probaby introduced by DKANs retrieveAll().
Or you can change the sort to another property of the feed, like "title", if you put the "_sort" part like this in the schema json:
"_sort": { "title": "baseSortAsc" },
This would sort the datasets by title from A to Z.
-
stefan.korn β
committed 70953e2a on 1.0.x
Issue #3524854 by swirt, stefan.korn: Warning Undefined property:...
-
stefan.korn β
committed 70953e2a on 1.0.x
- π©πͺGermany stefan.korn Jossgrund
warning should be gone and date sorting fixed like mentioned above, also a small fix for the "desc" sort.
- πΊπΈUnited States swirt Florida
Thanks for the background and options. I wonder if there is no pubDate we could provide a fallback by grabbing a reasonable date from some other source like 'modified' or entity->updated, because I do like the concept of having the rss sorted by date.
- π©πͺGermany stefan.korn Jossgrund
Okay, I will be thinking about this a little more.
Maybe it would be best to allow to provide one's own sorting function via extending in your own module. I will need to implement a hook or plugin solution for this.
Another approach outside of DKAN RSS would maybe to control this via dataset schema yourself. Maybe one could introduce a property to the dataset schema, that holds the date as a "computed" value that uses for example issued as first option, modified as second and entity->updated as last resort.