I’ve written a plugin which exports page content from various fields. By default, it only exports the title and text fields, but I’d like to be able to cycle through the other fields and extract that content accordingly.
My issue is that I need to determine whether a field contains structured YAML data (such as one or more URIs pointing at related pages) or just text (whether it’s a date or email address and so forth.)
Is there built-in way to check whether a field contains structured data (specifically structured list of URIs) or not?
Of course you could check if $page->somefield()->toStructure() returns a structure Object, but I don’t know if that makes sense to do that for each field, let alone other types of fields.
Don’t think it would be very performant to test each field for each potential field type.
If you have chosen field names wisely, you could probably create a mapping of field names to field types.
Yes, I agree. This didn’t make much sense after I took a closer look at the problem.
I ended up creating a definable array as a config option where the user can specify whether a field contains textual data or a YAML list of related articles or pages.