"For each" & "For all" field formatters
The 2 field formatters are very similar.
ComponentEachFormatter, we loop on each field item:
foreach ($items as $field_item_index => $field_item) {
$this->setComponentSettingsAltered(...)
$build[] = $this->buildComponentRenderable(...);
}ComponentAllFormatter, no loop:
$this->setComponentSettingsAltered(...)
$build[] = $this->buildComponentRenderable(...);
For information, the current ui_patterns_field_formatters module
is not "proposing" ComponentEachFormatter when the field has a single value cardinality.
Anyway, let's discuss and clairfy what we want to achieve here:
- Are we sure the 2 formatters have the same sources?
- Are we also working at the field property level with ComponentAllFormatter?
- ...
Simpler and shorter source naming
No need to recall the entity in the naming of sources: “Content article Image: Width", “Content article Image: Height"... We already know we are formatting a specific field from a specific content bundle.
The base plugin is enough: "Field property: Width", "Field property: Height"...
“Formatted value” source for slots is missing
We pick a field formatter, configure it and the result is the renderable we can put in a slot.
The context is not applied in Views
When using a field formatter in view fields, we see the properties of other fields. See #3440278: [2.0.0-alpha3] Field Formatters : views, nesting & context handling
Is it possible to set a generic "universal" system instead of just covering views' context?
Issue fork ui_patterns-3440319
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedComment #3
pdureau commentedComment #5
pdureau commentedComment #6
just_like_good_vibesHello,
here is a quite deep modification of the sub-module ui_patterns_field_formatter,
in order to tackle several issues, and stabilize.
A lot of code has been removed, according to the current or related issues, and also some simplifications has been introduced.
There are less generated ui patterns source plugins (at least we get rid of the "by bundle"),
context has been greatly improved to allow field formatters to work inside view fields and more.
Some new helper functions in field formatter classes have helped the retrieval of settings and context values.
Comment #8
just_like_good_vibesComment #9
pdureau commentedComment #10
just_like_good_vibesMore code was added to entirely cope with questions from issue #13440310
Comment #11
pdureau commented"For each" & "For all" field formatters
✅ ComponentEachFormatter is not present when the field has a single value cardinality
However, let's discuss and clairfy what we want to achieve here:
Simpler and shorter source naming
✅ The naming is now "Field property Width", "Field property Height"...
It would be better with ":" between the deriver and the property label: "Field property: Width", "Field property: Height"... I will do the commit.
“Formatted value” source for slots is missing
✅ it is present and is named "Field Formatter".
However:
The context is not applied in Views
See #3440278: [2.0.0-alpha3] Field Formatters : views, nesting & context handling
Comment #13
just_like_good_vibesHello again, just to summarize what happened in the last hours.
Thomas added some refactoring today, and i just added a few more commit on top of that during the two last hours in order to simplify a little and correct a few remaining bugs.
The current state is not totally perfect but worth it compared to the past.
This MR should at least cover all the comments referenced by this issue and the three other issues mentioned in the related issues sections. Many thanks Pierre for your precious reviews and comments.
Comment #15
pdureau commented