I’m looking for a way to validate not only the current edited item (ie. Page, or Article) but also fields of its related files. What I mean: each related file can have its meta fields, like alt attrib - or, like here I have - the “image_license” droplist, which is set to required: true
The thing is, that Kirby allows to create an article, to upload a file, and then when saving - it doesn’t validate that file’s fields - so it actually allows to save the article not fully validated. It only validates the direct fields of the article, but the file’s fields are only validated when I open the file details - but I need that to block saving the article, if its sub-items like file attachment is also not fully filled up - these must be filled too.
On the screenshots below example - the “Image license” field is marked as required, but checked only in this view. It could be also checked / expected to be filled up directly on that image upload screen, where it checks file type - but I also couldn’t find a way to do that.
How that can be achieved? Possibly without modifying Kirby source code, but with plugins or configuration
Did I describe that clearly? It’s a simple thing, but maybe not that obvious to explain.
I can’t find that information available to be checked anywhere, I’m debugging the incoming parameters, trying misc hooks, page.changeStatus:before, page.update:before, but the passed vars doesn’t contain the data of the ‘files’ field anywhere
What else can I try to get them? Do I need to fetch them somehow manually at the hook?
There’s no actual validation code, what I’m saying is that such information I need to validate is not coming to the hook, nowhere to be found in the incoming variables. I’m setting a debugger breakpoint on the first line and digging in the incoming data looking for the data there, but it seems that doesn’t even work like this, the images which I upload to the Article is not even treaten by Kirby as an Article change, it just immediately adds an image, without need to submit the Save button, which doesn’t even appear like when you change some text in the Article
Are you even uploading to a field, or rather to a files section? If you have no files field, then you need to validate all files attached to the page, i.e. $page->files(), or $page->images().
Well, my idea was not to react to a page update but rather on the page getting published. If any image metadata is missing at that point, show an error message that data is missing.
Page update only kicks in if you make change to the page content, i.e. if you have a files select and select a file or change the selected files. It won’t kick in if you have a files section (as that does not constitute a page update).