Open bnomei opened 7 years ago
This is something I'd hoped to implement from the beginningā a "soft getter" of some kind, that would accept an array of arrays or "accessors," like this:
Architect::get('blueprint', [
'nested.path.to.get', # Or, ['nested', 'path', 'to', 'get'] if you're all about verbosity!
'fallback.nested.path.to.get',
'third.fallback.to.try'
], 'Default Value');
Does this describe the kind of functionality you'd want?
i do not need the fallback, but the default value would be nice. in my case i need to get an option (even a nested one like with validate/match
of a field dynamically but if it does not exist it should return null
. kirbys 'magic'-field-methods $page->fieldname()
work similar and i think the structure-type ($page->content()->toStructure()
; no nested) as well.
if( $matchForParsley = Architect::get('blueprint', 'fieldname.validate.match', null) ) {
// do something
}
when constructing my forms based on the blueprint I actually iterate over all fields defined in the blueprint and parse all their options flat and nested. but using yml arrays and a recursive function its a bit messy. maybe the architect could return a kirby-collection-object? then filtering etc. would work out of the box.
getting the labels is very useful indeed but in my case i needed a lot more from the blueprint to generate dynamic frontend forms matching the panel blueprint. especially the
required
setting and thevalidate
with its propertymatch
to create regex for parsley.getting that with the direct yml array is a bit hacky since the
match
propery was not needed in some blueprint field definitions.i ended up with lots of if-clause testing and
a::get()
but maybe you can think of a better solution?