Hello,
I am working on a plugin which only edits the frozen URI.
I can do everything I need to do when the document is only being updated, because the internal value of the URI has already been generated and I can do what I want with it.
The problem is when my plugin runs for a NEW resource. I am using the OnBeforeDocFormSave event because I'd like to change the value before it gets saved to the DB. However, when a NEW resource is being saved for the first time, the auto-generated URI has not been set yet, it is blank, so I can't run my plugin code to change it.
I have look high and low for an answer, API function, resource method, something, to be able to generate this myself by I can't find it. I can use the cleanAlias method but that only generates an alias string and doesn't check if the alias already exists. Generating the URI is more complex because of FURLs and FURL path and parents/containers, suffixes and all that.
I know there is the makeUrl API function but this requires the ID, which is not created yet for a new resource when it is first being saved. Or is it? I tried using
but it didn't work so I assume there is no ID yet.
The only solution I can think of is use OnDocFormSave so that (I'm guessing), both the ID, and the auto-generated URI would be available. My complaint here is that once my plugin makes it's changes to the resource, it has to then save it immediately a second time. I guess that is how it would work, since the document already saved, and I would change the URI, I would be forced to save it again. This seems like it would take more time and resources to save a document twice, instead of editing values before it gets saved.
So my question is basically, am I able to access the MODX API to generate the exact same URI that MODX would create anyway when a document is saved so that I can BOTH turn on the frozen URI checkbox, AND set the value, BEFORE the document is first saved?
OR will I be forced to use the OnDocFormSave event and have to save all my documents TWICE when my plugin runs?
Thanks!