-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advanced field type schema #306
Comments
The Component Schema project is an option here; see #296. It's based on core's configuration schema API, itself modeled on Kwalify. I've just updated #296 with further details on how Component Schema works. If there's interest I'd be happy to contribute to integrating Component Schema and UI Patterns. |
@nedjo Interesting! I am looking at the schema here: One thing I notice is that fields/variables that expect html or render element are just marked as "string". I would prefer if there was a dedicated type for html.
Another question would be if or how patterns and components could be used together, or if one should be seen as a replacement of the other. |
Yes. So far, the custom schema types are mainly focused on the task of processing values to reduce the need for logic at the template level. For example, there's a
It's relatively easy to extend the existing schema types as needed, either directly in Component Schema or in another module. They work just like core's configuration API schemas.
I think that we could use just the variables schema directly in UI Patterns. That is, define the variables as That might open two potential paths:
|
Thanks @nedjo !
Ok, seems like something we could figure out and improve over time.
I could be mistaken, but I think one difference is that every ui pattern is registered as a theme hook, whereas components are just templates. So it might be a good idea to only declare ui patterns that actually need to be ui patterns, and leave the rest as pure components, so not to pollute the theme registry. I am not sure about the exact performance or memory impact. Another difference is that ui_patterns are exposed to the site-building UI, e.g. as ds field templates or as views plugins. (This is not ideal, and I think one limitation is the unspecific field types.)
Going to make sure I understand correctly..
So a front-end developer would create a ui pattern with a Currently the "fields" keys also contain "preview" values. I wonder if the component variables schema also supports this, or if we would need to find a different solution for this.
(I would call this an "adapter layer") |
I am interested in this for multiple reasons:
|
So I would clearly be interested :) |
I suspect you're right.
Correct. Before starting work I evaluated UI Patterns as a potential base but wasn't able to work with its limited
That sounds doable. It might open the option of doing integration in a separate module project rather than directly in
There isn't currently a preview. There is something partially analogous: the styleguide integration, which allows defining a template to be displayed in a styleguide.
Yes.
Probably not, at least not without further development. A main issue is the relative complexity of variables in Component Schema vs. the single-level list of fields currently supported in UI Patterns. Like the configuration schema API they're based on, Component Schema variables can be nested through mappings and sequences. This means:
Also, some of the Component Schema variables aren't necessarily intended to map to incoming data like entity fields but instead are more like settings. This gets into territory partially mapped out in the UI Patterns Settings module. Also, I haven't yet looked at registering libraries per component. One option would be to follow exactly the model used in UI Patterns, so that part at least would be directly parallel in the two data structures (component, UI pattern).
Probably only some. That might be as simple as adding a boolean key to the component definition such as |
These couple of Drupal core issues (both long since stalled out) are related: |
I imagine something different: Instead of producing a form for an arbitrary pattern, we would filter patterns that match a given schema requirement. E.g.
The field names / keys can be arbitrary, there would be some adapter logic to map fields. E.g. it could be "title" in the pattern, but "label" in the subsystem that wants to use the pattern. If I were to plan this from scratch, perhaps I would instead start with these common types, and then the patterns should follow that: E.g. "labeled elements", "labeled element", "list".. A pattern that goes beyond these basic types should probably be split up..
I think it can be useful to distinguish "data input" vs "settings" when defining the schema. |
Wow, I like this idea. The most straightforward way to integrate may be to start in Component Schema. I've opened an issue there and tried to sketch in some potential steps: [meta] Integrate with UI Patterns module. I probably haven't quite captured everything you were suggesting. Please wade in and clarify.
At least tangentially related: I've been mulling over how to handle the need that comes up in multiple components for a flexible container for content. I opened a related issue on Component Schema: Provide a standard way of handling arbitrary content. |
I already commented in the linked issue. |
Basic integration of Component Schema and UI Patterns is largely complete, see [meta] Integrate with UI Patterns module. While that doesn't in itself accomplish everything discussed in this issue, it does open up new possibilities. |
I don't know if this is the place to ask. I don't know how to check the contents of a variable in my pattern file. I think that's the discussion, right? |
Quick summary
Define how a structured field type can be defined in a *.ui_patterns.yml file, so that other modules can use this information.
Background
When defining a pattern in a
*.ui_patterns.yml
file, there is an entry'fields'
, where in each field there is an entry'type'
.In the docs, the following is said about
'type'
:This means currently the value does not have any effect.
There is no clear definition how a field type should be described.
There is no way to describe "structured" types, e.g. "array of items, where each item has the following fields".
Some patterns I have seen use value objects, but I don't think there is an agreed-upon format to describe this in the yml file.
Problems
Developers don't know what to put in the
type
definition in a*.ui_patterns.yml
file.Consuming modules cannot reliably use the information, because it could be anything.
E.g. a module that renders a list of items (e.g. field items) cannot filter the available patterns to only show those which have a "list" field.
Modules with dynamic data mapping, if a user chose the wrong pattern, send data to a pattern field that expects a different data format.
This can cause errors or misbehavior. E.g. a render element is sent to a pattern that expects a list of items, and then it would attempt to render the properties...
Desired behavior
A well-defined format to describe structured fields in pattern definitions.
Then other modules can pick this up and send make sure that the data sent to the pattern has the correct format.
Examples:
Proposed change
Field type format
A well-defined format to describe structured fields.
Possible formats:
<field name>: type: "\Acme\Foo\Timestamp"
for value objects.<field name>: type: render[]
for an array of render arrays.<field name>[<key>]: "\Acme\Foo\Timestamp"
to document nested values.Built-in plugins
Change the DsFieldTemplate plugin to only accept list-like patterns.
Create a views style plugin that uses list-like ui patterns.
The text was updated successfully, but these errors were encountered: