I have created a plugin to store author bios and then output them in various pages. That part is working great. I would now like to be able to create page collections based on author.
I’ve had this working before by manually setting up a new taxonomy filter of ‘author’ and adding to each page’s frontmatter per https://learn.getgrav.org/16/content/taxonomy#taxonomy-example.
Now I would like to do basically the same thing, but via the plugin’s php script. So far I have added the ‘author’ taxonomy filter via onPluginsInitialized:
$taxonomies = $this->config->get('site.taxonomies');
$taxonomies[] = 'author';
$this->config->set('site.taxonomies', $taxonomies);
Then I am updating individual page taxonomy via onPageInitialized:
$page_taxonomy = $page->taxonomy();
$page_taxonomy['author'][] = $header->aura['author'];
$page->taxonomy($page_taxonomy);
I have one page where I’ve set an author value in the frontmatter. I have verified that the above code is updating the contents of $page->taxonomy. However when I create a page collection filtered on author e.g. /blog/author:shawn-kendrick the collection is empty.
The full code is available here: https://github.com/matt-j-m/grav-plugin-aura-authors
This morning I went a step further thinking perhaps I need to refresh the overall taxonomy map, so I added to the above onPageInitialized
$taxonomy = $this->grav['taxonomy'];
$taxonomy->addTaxonomy($page, $page_taxonomy);
But still no good. I have dug down into Page::collection and found that when iterating through the blog child pages (lines 2714 - 2726 in system/src/Grav/Common/Page/Page.php) they are all being excluded from the collection by
if (empty($page->taxonomy[$taxonomy])
So apparently $page->taxonomy is being dropped/refreshed/overwritten after my plugin edits it. Is there another way around this, or am I trying to achieve the impossible? Thanks in advance!