I have a
Tree model that’s a list of document groups/categories. One of the subfields is a
Set, which contains the documents inside the group. What I want is a page that lists all the groups, each with a list of the documents it contains as links to view the document on another page. Further, I need the document links to be permalinks, as they’ll also be posted elsewhere.
Building it, everything was going great until I hit the document links. It seems
Set entries don’t have their own
_id nor any other way that I can see to reliably identify a particular
Set entry from its peers (given array position is mutable). Without that, I’m not sure how to build the links, since I need to pass a parameter to the document page identifying which doc to show.
I guess my first question is: am I missing something? Is there a way to identify
Set entries among peers that I overlooked? Maybe a setting I can toggle that would be helpful? Or some other solution?
As a workaround, I think I can add an extra field to the document items to serve as an ID field. It’s a little ugly but would work if I can get it reliably populated. Which leads to these questions:
Can I provide some magic dust in an options or meta JSON field on the
Setitself, on the items, or on the ID field, that would auto-populate the field with a calculated hash or similar?
Reading a bit, it sounds like Cockpit is extensible enough that I can build an addon to do the population, or perhaps to extend the
Setfield as a new field that includes an
_idvalue. But I have no idea how to get started – I’m just getting started with Cockpit itself, and the docs don’t have anything about addons. I’ve been looking around, but about everything I find is for v1, and I understand v2 was a major update with significant, incompatible changes. I’m very comfortable with PHP, so that’s not a hurdle, but a clean, secure starting point would be extremely helpful.
On a closing note, if I’m not overlooking how to enable an an
_id field, I’d like to propose this addition as a feature request. Along with plenty of use cases similar to my immediate one, I suspect this would be extremely helpful in lots of ops use-cases, such as backup or data syncing solutions.