The field_view_field() / field_view_value() functions would make much more sense as view() methods on FieldItemList and FieldItemBase respectively (and added to the respective interfaces)
The phpdocs should make clear that, like the former functions, those methods are intended for one-off display of isolated field values in specific cases, but should not be used instead of entity_view().
Most arguments can now go away :
- $entity can be accessed by $this->getEntity()
- $field_name is $this->name,
- $item is $this
- $langcode is $this->getLangcode() (no need to specify the requested language as a param, the caller needs to set the entity to the expected language first, then calls view() on one of the fields / field items)
--> FieldItemListInterface::view($display), FieldItemInterface::view($display)
This could be a "relatively advanced" Novice task :-)
Comment | File | Size | Author |
---|---|---|---|
#30 | field_view_field-2134887-30.patch | 32.75 KB | plopesc |
#29 | interdiff.txt | 2.91 KB | yched |
#29 | field_view_field-2134887-28.patch | 32.71 KB | yched |
#23 | field_view_field-2134887-23.patch | 34.32 KB | plopesc |
#9 | field_view_field-2134887-9.patch | 30.08 KB | zwischenzug |
Comments
Comment #1
yched CreditAttribution: yched commentedComment #2
fagoI'm hesitant to adding the view logic of fields to those classes also - it's like letting the data module render itself. I'd prefer a separation here, as we do it for entities as a whole. I'd be fine with a shortcut method though.
So instead, it should go on the entity view builder imo. We do the same for access already - both entity+field is handled via the respective controller.
Comment #3
yched CreditAttribution: yched commentedPutting the methods on EntityViewBuilder, with shortcut view() methods directly on FieldItem / FieldItemList: right, makes more sense indeed.
Then we'd need two methods on EntityViewBuilder though:
LongNames-- ;-)
Or maybe viewField() / viewFieldItem() ?
Comment #4
yched CreditAttribution: yched commentedStarted working on this with a co-worker, he should post an initial patch shortly.
Comment #5
zwischenzug CreditAttribution: zwischenzug commentedComment #6
zwischenzug CreditAttribution: zwischenzug commentedNot finished yet ...
I worked with yched,
Remains to be done :
- Transfer the code of the two methods (FieldItemBase::view() and FieldItemList::view()) in 'EntityViewBuilder'.
- Replace existing calls to field_view_field() / field_view_value() and remove the functions
- Add PhpDoc.
Comment #8
zwischenzug CreditAttribution: zwischenzug commentedReroll
Comment #9
zwischenzug CreditAttribution: zwischenzug commentedCompletely replaced the old functions.
Still todo: move the actual implementations to EntityViewBuilder.
Comment #10
zwischenzug CreditAttribution: zwischenzug commentedThere was a merge conflict.
Comment #13
yched CreditAttribution: yched commentedbeta target, since this is blocking #2067079: Remove the Field Language API
Comment #14
yched CreditAttribution: yched commented"beta target" -> bumping priority accordingly
Comment #15
zwischenzug CreditAttribution: zwischenzug commented- FieldItemList::view() implementations moved to EntityViewBuilder::viewFieldItemList().
- FieldItemBase::view() implementations moved to EntityViewBuilder::viewFieldItem().
- Completely replaced the old functions.
- field_view_field() and field_view_value() deleted.
Still todo :
- some phpdoc.
Comment #16
yched CreditAttribution: yched commentedWill need a reroll after #2075185: When an entity is in-place edited (i.e. saved), other instances of that entity on the same page are not updated (no propagation), that modified the place where EditController calls field_view_field() - see http://drupalcode.org/project/drupal.git/commitdiff/ebad0cd9420c5d6e5166...
Comment #17
effulgentsia CreditAttribution: effulgentsia commented15: field_view_field-2134887-15.patch queued for re-testing.
Comment #19
effulgentsia CreditAttribution: effulgentsia commented+1 to this issue, but #2067079: Remove the Field Language API landed without this, so reverting #13's and #14's issue attribute changes.
Comment #20
plopescRe-rolling patch.
Also adding methods to
EntityViewBuilderInterface
. This decision leds to duplicate code inEntityViewBuilder
andBlockViewBuilder
. Could be a good idea create a new abstract class implementing these methods and extending it bothEntityViewBuilder
andBlockViewBuilder
to avoid duplicate code?Regards.
Comment #21
yched CreditAttribution: yched commentedThanks @plopesc.
#2167267: Remove deprecated field_attach_*_view() is probably going to change the content of field_view_field() quite a bit, so it might be wiser to wait for that one.
The discussion there could also impact where the replacement methods end up...
So, postponing...
Comment #22
andypostdependency commited
Comment #23
plopescQuick re-roll of 20.
Let's see testbot...
Regards
Comment #24
xjmI'd actually still suggest we make this a beta target.
Comment #25
jibran23: field_view_field-2134887-23.patch queued for re-testing.
Comment #26
yched CreditAttribution: yched commentedThanks for the rerolls !
Updated patch:
That check is useless now that we receive a FieldItemList object instead of [an entity + a field name]. If that FieldItemList object exists, then we can reasonably assume that the field exists in the entity.
Same here.
Hm - not sure why BlockViewBuilder needs to duplicate the implementations from EntityViewBuilder.
Trying without it.
Looked into this. The rendering pipeline in \Drupal\field\Plugin\views\field\Field could use a serious cleanup, but for now clarified the multilingual logic a bit.
removed leftover debug()
Let's see what testbot says.
Comment #27
yched CreditAttribution: yched commentedGreen. This should be ready to go.
Comment #28
andypostThe main confusion here is that new methods accept 2 different arguments, both optional
Maybe it make sense to check the usage and split them?
what is the reason for this confusion?
same here?
Comment #29
yched CreditAttribution: yched commentedPointed by @swentel on IRC : some docs referred to an incorrect method name.
@andypost: This is how field_view_field() / field_view_value() work currently, and there are use cases for both.
Splitting that would mean 2 methods on FieldItemList, 2 methods on FieldItem, and 4 methods on EntityViewDisplay().
I'd rather leave it alone :-)
Comment #30
plopescRe-rolling after #2002134: Move TypedData metadata introspection from data objects to definition objects
Comment #31
swentel CreditAttribution: swentel commentedOk, let's do this.
Comment #32
yched CreditAttribution: yched commentedThanks for the reroll !
This will need a draft change notice before it gets committed. Can't write it before monday though :-/
Comment #33
swentel CreditAttribution: swentel commentedJust created the draft notice, but without any usefull body for now, hopefully that helps, will try and see if I can add more data tomorrow on the sprint.
Comment #34
webchickIf we don't have a change record that's not a "todo", this isn't RTBC. Sorry.
Comment #35
swentel CreditAttribution: swentel commentedUpdate record, going to trigger a re-test to be sure as well.
Comment #36
swentel CreditAttribution: swentel commented30: field_view_field-2134887-30.patch queued for re-testing.
Comment #37
yched CreditAttribution: yched commentedThanks @swentel. Expanded the change notice a bit.
Comment #38
webchickAwesome, thanks for the fast turnaround on that!
Committed and pushed to 8.x. Thanks!