ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Blueprints: validate keys/names of tabs/columns/fields

Open adamkiss opened this issue 4 years ago • 3 comments

One of the biggest and most frustrating moments is when I use disallowed/unsupported name for my fields. It doesn't happen often, but it does happen occasionally and it's superfrustrating to deal with.

Struggling with the query language … Is it possible to query for a files field? Something like: query: page.image.toFile() or query: page.image.first.toFile() Renaming the field from image to img solved it :no_mouth: —(example from Slack:)

~~If validation is "too much dev time(TM)", perhaps prominent section of docs related to blueprints could be designated for a list of reserved/problematic words.~~

My bad. The notice is here: https://getkirby.com/docs/guide/blueprints/fields#naming-fields

Thank you.

adamkiss avatar Jul 17 '20 13:07 adamkiss

ran into the same problem earlier. would appreciate this!

robinscholz avatar Jul 17 '20 13:07 robinscholz

This is super difficult to solve. The issue haunts us since Kirby 1 and there is no good solution:

  • We cannot display an error in the Panel for these fields as the fields themselves are completely valid, they only cannot be accessed directly in templates.
  • When a method like $page->image() is called, it doesn't know whether the developer actually wanted to access a field.

Possible solutions are:

  • a list of field names that have this problem – that already exists as the list of $page methods in the reference
  • changing the docs to use ->content() everywhere as that will always work, however the syntax is longer and not required for most fields
  • a more prominent warning in the docs in more places

A true solution in the core is very difficult for the mentioned reasons.

lukasbestle avatar Jul 18 '20 19:07 lukasbestle

I know the idea of a health check plugin has been floating around for a while... that certainly would be one good check to cover in such a plugin (loop through all field names and check against method list).

distantnative avatar Jul 19 '20 08:07 distantnative