U4-10581 - Idea to add ability to decorate property types so other packages can "do stuff" to them

Created by Pete Duncanson 24 Oct 2017, 09:51:03 Updated by Lars-Erik Aabech 24 Oct 2017, 19:02:19

Had an idea yesterday and need to just flesh this out a little and get some brains on it. I'm not sure if it falls into the "waaaaaay to hard to do" or "thats easy you can just do X" category.

Context: I wanted to create a way to warn users that they haven't but should fill in some fields. This is not a mandatory field, its more of a warning or hint "Hey, you've not added any meta data, you might want to do that..." type stuff. It shouldn't stop the page from being published but it guides the editor to making a better page, lets call this the "Hint field" feature. This is what sparked off my idea, this is not the idea itself.

So I got to thinking what I need is a way to add a boolean onto property types to say "Is this a hint field?" and ideally some text for the message it should show. This can be added to any property type. Then on save I can hook into all the property types and see if the field is set and show a warning if nothing it there. Sounds doable...however...there is no known way to easily allow in the UI a way to add additional (or meta) data to property types except those that it originally had baked in.

Is there a way to easily allow in the Property Type editor the ability to edit addition fields/settings of some of these meta fields which other packages could add in.

I pondered a config file, or a database or adding another special property type to the doc types which although they work it make it a little clunky to get this working. Baby steps might be the way to go though in which case I'm thinking of leaning towards a config file for ease. Ideally this meta data idea would be a separate package that just handles the meta data magic and then other packages can reuse it if the need to decorate property types.

Thoughts and ideas please :)

Comments

Karl Tynan 24 Oct 2017, 10:06:28

If it isn't possible to add meta data to properties, how about creating a new "hidden to the user" data type that is aware of the doctype? This could then have a list of properties that you can provide additional meta data for? For example, a checkbox next to "contentTitle" that is not required and a textarea that could be used based on an action (i.e. no data entered).


Lars-Erik Aabech 24 Oct 2017, 19:02:19

Karl's suggestion will go a long way. It'll give you a magic UI with the datatype prevalues.

I'd go with some global configuration with a schema something like:

{
  "page": [
    "seoTitle",
    "seoDescription"
  ],
  "contactPage": [
    "openingHours"
  }
}

AFAIK It's quite difficult to detect saves for now, though. I wrote up a script with Jeroen a while ago that might help: https://our.umbraco.org/forum/developers/api-questions/74724-check-if-node-has-been-saved-and-published-in-property-editor#comment-239145

You could just loop over the aliases in the config for the content type and do something if they're empty.

When it comes to empty - you probably need a map of property editor type names and functions that check for "emptiness". It's not always gonna be a blank string. Might be an empty array, object, null, blank, zero etc.

UI-wise, you're left with where to store it. DB is overkill for such a small config set. Files will give you trouble in distributed scenarios. Azure storage? A prevalue? Beats me. :) I'd deploy a manually edited JSON file to all servers.

Good idea though.

On a sidenote: I think maybe Richard's SEO checker has something very similar?


Priority: Minor

Type: Feature (request)

State: Submitted

Assignee:

Difficulty: Normal

Category: Extensibility

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: