Problem/Motivation
Default, Inline, Table, HTML and List template fully renders the subfields, i.e. their label is shown (and not the value), the referenced entity is shown with a link to it (and not just the referenced entity ID) and so on.
When we choose "Custom template", there is a free HTML (wonderful option) but replacements are done only on the values of the subfields.
Steps to reproduce
Create a custom field with a subfield A as a select list (value/label pairs) and another field B as an entity reference.
In manage display, choose one of the first four ones templates: A is shown with its label and B is shown with the title/label of the referenced item.
Now in Manage Display choose the Custom Template and use the replacement tokens to display A and B: only the value of A can be shown (not its label), only the entity ID referenced in B can be shown (not its label and link).
Proposed resolution
Add another token to fully show the subfield values.
THANKS!
User interface changes
N/A
API changes
N/A
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | Screenshot 2024-11-19 at 5.06.01 PM.png | 233.07 KB | apmsooner |
| #9 | Screenshot 2024-11-19 at 5.02.19 PM.png | 119.52 KB | apmsooner |
Issue fork custom_field-3476033
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
apmsooner commentedI have a working solution for images by adding some additional tokens. It might be overkill but I wanted to support image styles if we're gonna do this. I think the entity reference solution will be similar but tokens would be by view modes. What do you think of the screenshots depicting how this would work?
Comment #3
giuse69 commentedHi, yes, the approach for images adding new tokens seems very good to me. Besedes references, also select list should be added to display labels isof values.
thanks!
Comment #4
apmsooner commentedThanks for the feedback. For better UX, i'll put the tokens into collapsible fieldsets for each subfield. I should have a patch ready to review in the next few days or so hopefully.
Comment #5
chucksimply commentedWould this patch apply to other entities as well? Taxonomy, Node, etc?
Looking forward to this feature!
Comment #6
apmsooner commentedI got a little sidetracked with day job but I expect to get back into this soon. @chucksimply, the plan would be to provide support for all field types and reference types. I left off with researching whether the token module is viable option for greatest flexibility however it may be overkill for basic needs and for example entity rendering tokens could simply be just the label and available view modes. Trying to think about this in simplest way to not overcomplicate but also provide just enough for common needs.
Comment #7
apmsooner commentedComment #8
apmsooner commentedI'm close to getting this ready for patch review. I just need to finish up some of the logic but the solution for this is going to be optional advanced tokens support via the token module which will provide you full entity token access as well as global tokens. Here's a new screenshot for how this is going to look. I hope those of you following this are still interested in testing out when ready.
Comment #9
apmsooner commentedComment #10
giuse69 commentedyes, I am available to test when ready
Comment #11
chucksimply commentedYup, ready as well.
Comment #13
apmsooner commentedAlright feel free to give it a go! Some things to know:
Comment #14
giuse69 commentedit seems to work great when the custom field is belonging to a node, it seems not to work (no token available except the global ones) when the custom field is belonging to a taxonomy term, maybe it needs to be extended to taxonomy?
Comment #15
apmsooner commentedLet me test that. I think its just the naming conventions are different with taxonomy terms for the token types.
Comment #16
apmsooner commentedThat commit will fix it for you. Just pull down the latest.
Comment #17
giuse69 commentedWith the new fix, it works for taxonomy in entity display, but I still don't see the formatters menu choice to appear in views when picking a subfield as field in the view
Comment #18
apmsooner commented@giuse69, The views subfield issue is unrelated and not going to be addressed in this issue. While I'm not saying its a valid request to support views subfield formatters, I don't really see a huge need to even render the subfields in views on their own. I guess I don't quite understand what you are ultimately trying to accomplish but maybe theres a better way of going about it.
Comment #19
giuse69 commented@apmsooner: you are right, the views subfield issue is not important and I can use the overall custom field, but I can't make the overall custom field work in a specific scenario: a view on taxonomy terms where the custom field is multivalued and each instance includes a text or integer subfield AND an entity reference subfield referring to taxonomy terms as well. The view uses a relationships to connect terms of one vocabulary to terms of another vocabulary.
If I pick up individually the two subfields to be shown in the view, their raw values are correctly shown (and no choice of formatters but no problem as you say).
If I pick up the overall custom field, nothing is shown, even with default formatter. If I set the custom field to use the relationship, all related terms are shown (too many records as the join wouldn't be working correctly).
I made this test several times and on a couple of views of this type with same results.
Anything I can further test or you can check this particular situation?
thanks!
Comment #20
apmsooner commented@giuse69, Yeah i can't really visualize what you're trying to do so I won't recommend anything for you other than maybe try using a view of entities in a view mode where you have full control of the field output perhaps. It sounds like an edge case though that I don't think is common for other users and I'd prefer to really focus on prioritizing in other areas for now.
Comment #21
giuse69 commentedHi @apmsooner, I made a new and simple test with a clean scenario to describe how you can reproduce the issue. I don't think it's an edge case.
2 Vocabularies
VOC1: country
VOC2: organization with a custom field "items" to include countries belonging to the organization, subfields are:
-) "item" = entity reference to taxonomy term - country
-) "type= a string for type of participation to the organization
View
A simple view on taxonomy term country to show how many orgs the country belongs to
-) Contextual filter: Taxonomy term: Term ID
-) Relationship: subfield items:item of organization (Taxonomy term using field_organization_items_item)
Fields to be shown:
-) Name (of the organization) using the relationship
-) Subfield of the custom field items:item
-) Subfield of the custom field items:type
This works. BUT if I use the overall custom field items (default or any formatter) instead of the two subfields, nothing is shown.
Could you please look at this?
thanks a lot!
Comment #22
apmsooner commented@giuse69, i created a separate ticket for the subfield formatter settings in views: https://www.drupal.org/project/custom_field/issues/3489629. Let's keep that discussion out of this ticket as it is completely irrelevant to the token support in this ticket.
Comment #23
giuse69 commentedHi, the issue is not about subfields, It is for the overall custom field when used in a view for taxonomy terms with relationship. i hoped my last description was clear about that but maybe not.
Anyway ok for a new thread but the issue is differenti, let me know if I can change the title/description of the new one or you want me to open another one.
Cheers
Comment #24
apmsooner commentedI believe its a subfield issue. Just follow the other ticket and I'll have a patch over there soon that you can test out. I just can't do it in this same branch as theres alot of code involved that needs to be tested separately.
Comment #25
apmsooner commentedComment #27
apmsooner commented@giuse69, I created a patch in https://www.drupal.org/project/custom_field/issues/3489629 that you can play with. Follow that issue and post any comments you have over there going forward. Understand the patch is not complete but it may at least help you figure out if your issue is somewhat resolved by using the new subfield formatters vs. the field one. Please post there though as this issue is now already merged and marked fixed.
Comment #28
apmsooner commentedComment #29
chucksimply commentedFinally got around to using this new feature. All works great. Thank you!