Problem/Motivation
The list of view_modes is empty in dynamic_entity_reference_entity_view formatter.
Proposed resolution
Allow users to choose per entity type formatter.
Remaining tasks
None.
User interface changes
Users will have the ability to choose the per entity type formatter in dynamic_entity_reference_entity_view formatter settings.
API changes
API addition only
Data model changes
None
Original report by @SylvainM
The formatter can not found available view_modes.
Patch will follow
| Comment | File | Size | Author |
|---|---|---|---|
| #44 | list_of_view_modes_is-2729463-44.patch | 14.25 KB | jibran |
Comments
Comment #2
sylvainm commentedWith this patch, the select contains only the view_modes which are enabled for all referencable entities
Comment #3
jibranNice catch. We need tests here.
Comment #4
jibranThere is #2381993: Allow view mode or formatter to be selected per item in the widget to move this to widgets
Comment #5
ifrikI have a similar problem as described in #2743487: Allow more display modes besides default for "rendered entity" format.
I've tested this patch and it works for me. The dropdown menu now displays all those display modes that the selected entities have in common, including custom ones.
Comment #6
jibranComment #7
CTaPByK commentedPatch with test coverage.
Comment #9
CTaPByK commentedRemove unused imports and unnecessary permissions.
Comment #11
slashrsm commentedGreat progress! Few things:
It seems that the short array syntax is used in other classes of the module. Let's be consistent.
We should consider the case where selection is negated ("Exclude" checkbox is enabled).
Also add test coverage for that.
I assume that this creates intersection of view modes for all enabled types.
I think that it would be better to leave all view modes in there and add a description that would explain that the "Default" view mode will be used if the selected one doesn't exist for a given view mode.
Would also be nice to test this case.
Comment #12
jibranThanks @CTaPByK for the patch and thank you @slashrsm for the review. Yes, please use array short syntax everywhere.
I think we should have per entity type view mode.
node: teaser
user: default
taxonomy_term: term
Having one select field or multi-select field doesn't make much sense imo.
Comment #13
CTaPByK commentedPer entity view mode.
Comment #15
jibranWe have to update default setting as well.
Comment #16
jibranWe also have to override the
viewElementsto actually use it.Comment #17
slashrsm commentedYes. And if view mode configuration for a given entity type is missing we use default I assume.
Comment #18
CTaPByK commentedDefault settings is updated also as viewElements and tests.
Comment #19
jibranThanks for the updated patch only thing remaining is #15 i.e. override
defaultSettingsinDynamicEntityReferenceEntityFormatterComment #20
CTaPByK commentedYes my mistake, now defaultSettings is overridden.
Comment #21
jibranThanks for the patch.
I think this should be just
return array_fill_keys($options, ['view_mode' => 'default', 'link' => FALSE]). The parent doesn't give us anything so just leave it. Every view mode should have link setting and it is keyed by entity_type. Example can be seen at\Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::defaultFieldSettings();.Comment #22
CTaPByK commentedYes, i change link from bool to sequence of bool, default settings are updated and schema also.
Comment #23
jibranI meant like this.
Comment #25
CTaPByK commentedOh, ok, then i will fix failing test.
Comment #26
CTaPByK commentedTest is fixed i think and settingsSummary method is also fixed.
Comment #27
jibranThanks! for fixing the fails. Almost there. I made some minor string changes. Let's add some asserts related to these in
testFieldFormatterViewModes.Let's press update and assert the settings summary.
We should also check the labels of the select fields.
Comment #29
jibranMarked #2377841: Allow user to chose per entity type formatter. as a duplicate.
Comment #30
CTaPByK commentedCheck updating summary and labels are inserted in test. Test is green in my localhost.
Comment #32
jibranMaybe this will fix it.
Comment #34
jibranNow we have different fails.
Comment #35
CTaPByK commentedYes, i will try to remove this check of default view mode, but however its hard to test when test is pass in my localhost.
Comment #36
CTaPByK commentedTest is still green locally, but lets try like this.
Comment #38
jibranHave you tested it PHP 5.5? I have PHP 7 and it didn't fail for me as well.
Comment #39
CTaPByK commentedIm testing also in php 7, but a can switch quickly on 5.5. When i finish i will comment.
Comment #40
CTaPByK commentedIm tested with php 5.6 and test is green then i tested with php 5.5 and fails exactly like here, with same message...
Comment #41
CTaPByK commentedI think this is will fix that fails. Actually, ARRAY_FILTER_USE_KEY work from php 5.6.
Comment #42
jibranYeah just looked at it http://php.net/manual/en/array.constants.php#constant.array-filter-use-key.
Comment #43
jibranThanks for fixing the fails.
These are not correct.
Comment #44
jibranFixed #43. I think we should expand this test a little.
Comment #47
jibranI update the format summary text a bit, did some manual testing. Here are the screenshots.


Formatter settings
Formatter rendring
Thank you! committed and pushed to both branches.
Comment #49
jibranThe is an upgrade path for this change in open open_social. https://github.com/goalgorilla/open_social/blob/8.x-1.x/modules/social_f...