Sorry, AGAIN a question from me about handling and updating structure objects…
I have a a structure that holds credits (role and name) for a project.
Now I want to add a single row that is generated programmatically to this within my controller.
I thought I could use the StructureObject constructor, as documented here, but if I use that in my controller I get an error Class 'StructureObject' not found?
What is an easy way to add an extra row to the structure field? I don’t want to update the pages field permanently, I just want to add an extra row virtually within my page’s controller.
Gave this a try, the new row does not appear in the structure field when I loop over it. Even tried your specific code on the about page of the starterkit and the dump returns only the fields that were already there:
Ah, now it works. Also, $count = $structure->count()-1; should be $count = $structure->count() instead if the item needs to be added to the end, else the last item will be overwritten.
Thanks!
Why is structureObject missing from the aliases? Should I prepare a PR to add it or is it omitted on purpose?
Ok, but then should the constructor not be documented differently?
new Kirby\Cms\StructureObject(array $props)
And maybe a hint that the id field is required.
(Sorry that I keep pointing out stuff in the docs, but I think having stuff complete and consistent will help all users in the long term. I am very willing to prepare a PR as well)
No, you can’t change this, because this is generated automatically from the source code. The full class name is given below the headline. We would have to generally change this then.