I have a ModelAdmin
for a SilverStripe website and am a few levels deep in the creation through the CMS. For reasons in this model I need to get the paren->parent of this model being created before the object is created.
I could in theory get the URL and get the item id out of it by splitting the URL however this seems somewhat unreliable.
What is the best way to get the parent->parentID at model creation in the CMS ModelAdmin
?
Look at the problem from another angle:
If you have full access to the code, or can add a simple enhancement, create a session entry that stores the grandparent id at the time the grandparent is accessed, and then retrieve it that way.
It's open-source so should be a simple task. Create an observer that listens for when a grandparent ID is loaded, in the observer store that ID, then create a method in the observer to fetch the ID.
If that sounds like a lot of work, use the URL. The URL is safe to use as long as the links are solid. URLs are the cornerstone of routing.
HTH