Problem/Motivation
Theres not currently a way to modify the wrapping html tags in the formatter plugins. It would be nice to plugin to something like the fences module or create our own simplified version that can work with our plugins.
Proposed resolution
Research what fences and other modules are doing for form options to set tags, classes, etc.. and modify our templates to accommodate this feature.

| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Screenshot 2025-01-06 at 8.59.31 AM.png | 59.52 KB | apmsooner |
Issue fork custom_field-3496708
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 #3
apmsooner commentedPatch available for testing. Recommend clearing cache.
In the formatter settings for the 'default' formatter. Theres a new details element labeled "Style settings" under each field. These settings allow to set the html wrapping element and add additional classes.
Comment #4
apmsooner commentedComment #5
giuse69 commentedHi Andy, it works for me with just a small typo: when the label is shown when using the default formatter, an extra space/blank is added before the colon, like "label : value".
As a side note not directly related to this issue but to the formatter in general:
-) the custom formatter cannot be translated and it should be since we can write words in the template (both basic and advanced).
-) in the advanced template, I couldn't find a way to show the label of the subfield (I found no token for that), should it be added?
Thanks
Giuse
Comment #6
apmsooner commentedThanks, i just pushed up a fix for the extra space. Just get the latest patch and clear cache and should be good.
Other issues...
1. You're saying not the tokens themselves but the text you also put in there? Let me look into that for you as I didn't think of that issue honestly.
2. There are tokens for every label of subfield. It would be like this example: [node:field_testing:value:label]. In the token browser, you should be able to expand the subfield and see label.
ie explained format; [entity_type:field_name:subfield_name:subfield_label]
Comment #7
apmsooner commentedFor #1, Are you translating the configuration page for that I assume?
Comment #8
apmsooner commentedFrom what I can tell, it doesn't look like Drupal provides a way to translate display page settings. Might be out of luck on that one as I just don't see an option for that.
This module (no experience with it) sounds like it might be a better solution as it provides an actual field for setting tokens.
https://www.drupal.org/project/field_token_value
Fields are as you know translatable so would think this might work for you. I could look at doing something similar for custom field later but this might work for you now.
Comment #9
giuse69 commentedHi Andy, for #1... ok, Drupal effectively does not allow to translate display settings so my request is not easy. maybe allowing twig support in the template? That would greatly enhance flexibility of the advanced template, also enabling translation.
About #2, I mean the labels that represent the name of the subfield, not the labels/values corresponding to the raw values. I didn't find any token for the names of the subfields, the same output obtained with [:label] with basic template.
Comment #10
apmsooner commented1. Handling twig support in that field is something I don't want to do. If you're comfortable with twig, you can just copy the field templates from custom_field or even just have a higher level core field template in your custom module or theme that you can customize to your desire. This template formatter for custom field was never really meant to be a full on replacement for theming but more as a solution for simple output.
2. The labels are exposed in the token browser but if you're not seeing them, it may mean that you may have too low of a setting for recursion limit which the default in Drupal core is 3. If you are using paragraphs and such, you sometimes need to increase this to 4 or 5 maybe to get deeper into the tree. I've included a field that applies that in the advanced tokens settings for the custom template formatter that you could try modifying. Just know that increasing the recursion limit loads the tree slower.
Overall, I think going down this tokenized template route might not be the best solution for you and I'd probably recommend customizing your own field templates.
Comment #11
apmsooner commentedComment #13
apmsooner commentedComment #14
giuse69 commentedAbout #2, I can confirm you that I can't see any token for the subfield names, even with 5 levels depth. The practical example: a paragraph with a custom_field "CF" with a integer select list subfield named "status" that has value = 0 and label= "NO".
Here are the tokens and their outputs:
[paragraph:CF] =>
status
NO
[paragraph:CF:status] => 0
[paragraph:CF:status:label] => NO
[paragraph:CF:status:value] => 0
so no token contains the string "status" that is the name of the subfield (except for "paragraph:CF" but that contains all the custom field, not just the subfield name).
With the basic template, [status:label] outputs "status" as needed.
Any idea?
thanks
Comment #15
apmsooner commentedOkay, i was probably thinking about the list options label. Follow this task and I'll have a patch for you: https://www.drupal.org/project/custom_field/issues/3498012
Comment #16
apmsooner commented