(this is more like a brainstorming issue)

First of all: hook_ds_field_theme_functions_info() is awesome, and much underrated!
(elsewhere this is called "field templates")

Some use cases:
- Display field items in a "slider".
- Display field items floated next to each other.
- Display as a "grid" of boxes.
- Display as a numbered list.

In fact a lot of things that exist as a Views style plugin do also make sense for field items.
Esp. when the field is a multiple-value entityreference.
In an ideal world, you create a slider module once, and have it work likewise for field items and views rows. Then this can be reused on any site where you need a slider.

Unfortunately, the API has some limitations.
- Documentation is a bit hidden.
- The name is inconsistent. Is it "field template" or is it "field theme function"?
- You need a separate theme function per display "mode" (item returned in the hook). No way to let different modes use the same theme function.
- These are not real theme functions, are they?

I am not really sure what I want to ask for, but I imagine we could do more fancy stuff with field templates.
So I am starting this as an open-end brainstorming..

Comments

aspilicious’s picture

well...

You don't need different theme functions for each view mode. Each template matches one theme function. (so one for reset, minimal and expert)
Second of all these templates are kinda hardcoded in drupal 7. And it's not extensible at all...
I'm not planning, not at all, to change that for drupal 7.

I AM working on changes for drupal 8. I'll be using plugins to build the templates. The plugin will contain the form elements for the field UI and theme function based on the plugin ID (or some other key in the annotation) will be generated.

That way it's fully flexible and awesome. You only need one class and one theme function. :)

donquixote’s picture

You don't need different theme functions for each view mode. Each template matches one theme function. (so one for reset, minimal and expert)

I used the wrong word here.
Different theme function per "template". E.g. one for reset, minimal, expert, one for "slideshow", one for "grid", etc.

What I had in mind instead is to provide e.g. "grid" and "slideshow" as options next to "reset", "minimal", "expert", but let them use the same theme function.

The idea was to have a separate API to define "list templates", that is, components that can display a list of items. Then an adapter layer, so each "list template" would appear both as a ds field template, and as a Views style plugin.

So as a user of this API I only need to implement my template once, without even thinking about Views or DS, and then have it available both on ds and Views.

aspilicious’s picture

I'm not going to over-engineer this. With views in core there is also no chance for a universal layer. I'll keep in mind that you want to re-use theme function across different implementations.

donquixote’s picture

With views in core there is also no chance for a universal layer.

Why not?
All we need is a (contrib) module to provide the new API and then register this stuff as Views plugins with an adapter layer.
Afaik, different plugin in D8 *can* use the same plugin class. Or not? I think to remember a mechanic for that.

aspilicious’s picture

Thats exactly the amount of layers I don't want to introduce. And besides of that I don't want DS for drupal 8 to be dependant on any other module. But I'm always open for experiments.

I'm going to finish my simple implementation this year. Afterwards you can go wild with experimental code to proove me wrong :)

donquixote’s picture

Most of what I have in mind can live in a separate module, so you don't have to worry about it.
I am already happy if hook_ds_field_theme_functions_info() becomes as flexible as e.g. hook_field_formatter_info().

aspilicious’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev

Moving to Drupal 8 for now. Not relevant for drupal 7.

aspilicious’s picture

Status: Active » Closed (fixed)
donquixote’s picture

@aspilicious:
Just created a module which allows to define such reusable plugins.
https://github.com/donquixote/drupal-listformat

This is currently D7 only, but I see no reason not to port it to D8 once I'm happy with everything.