isaactopo / xmlsitemap

This plugin provides a straightforward approach to creating XML Sitemaps, especially for sites with multiple languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with routes and collection of virtual pages

squareclouds opened this issue · comments

hi there,

i am not sure if this is k4 related only or maybe because of php8+, but somehow i was getting an error with virtual pages:

strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated

and it is pointing to this line

line 13 in sitemap.php
$last_modified = $p->modified('c', 'date');

i change it to this:
$last_modified = $p->modified('c', 'date') ?? $p->content()->get('modified');

my use case: i am creating virtual pages from user profiles. for my workaround to work, when i create the virtual page i pass the $user->modififed() value to the content of the page (i didnt know how else to do it). with that, my modified line works fine. i create the page like this

$usercontent['modified'] = $user->modified('c', 'date'); // <--- here i pass the value, already with the right format

$newPage = Page::factory([
            'slug' => $nameslug,
            'template' => 'membervirtual',
            'model' => 'membervirtual',
            'parent' => $parent,
            'content' => $usercontent
        ]);

also on line 23 you could use the variable, and not call the page function again

line 23 in sitemap.php
<lastmod><?= $last_modified ?></lastmod>

this works of course because i can pass the value from the user to the virtual page, but i guess if you create the pages from some other source you have to see how to pass the value.

can you see if you can replicate? and if yes, do you maybe have a better alternative? (or just implement mine maybe and mention in the docs that the param modified has to exist in the virtual pages content())