Problem/Motivation
Split out from #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates.
Steps to Add a tag select list in string(plain text) Formatter :
- Go to any entity like node: https://your_site_url/admin/structure/types/manage/article/fields
- Add plain text field(for eg Sub Title) from manage field tab of content type, then go to manage display of content type:
https://your_site_url/admin/structure/types/manage/article/display
- Here you find the newly added "Sub Title" field & next to it, there is "format column" display where you 'll see now "Title" option visible in select list, along with it there is additional settings that you can configure by clicking "setting icon" that displaying next to it.

In additional setting there are two "format settings" are available :
- Link to the Content: if you enable the checkbox then this newly added field (For eg: Sub Title) content 'll be linked to it's node itself.
- Tag: In it, these options h1,h2,h3,h4,h5,h6,span,div are available to select, when this newly added field (For eg: Sub Title) content render then you 'll see selected tag 'll wrap the content on FE.


Proposed resolution
Instead of creating new TitleFormatter, add a select list to choose what tag to use in the existing StringFormatter
Write a test.
Remaining tasks
Review
UX review
Screenshots
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | After_settings_3470497.png | 232.84 KB | manibharathi ezhimalai ravi |
| #35 | Before_settings_3470497.png | 227.97 KB | manibharathi ezhimalai ravi |
| #35 | Patch_failing_3470497.png | 1.45 MB | manibharathi ezhimalai ravi |
| #35 | UI_changes_3470497.png | 555.64 KB | manibharathi ezhimalai ravi |
| #31 | fomatter-render-FE.png | 150 KB | pooja_sharma |
Issue fork drupal-3470497
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 #4
pooja_sharma commentedAdded title formatter as mentioned in proposed solution , this 'll add title formatter for plain type field for manage display , working on test coverage part in which cover if title formatter selected for field type , then it linked to title or not.on the basis of selected config.
Comment #5
pooja_sharma commentedAdded title formatter as mentioned in proposed solution & added test coverage as well for title formatter, apart form nothing seems to be left.
PLease review, moving NR
Comment #6
smustgrave commentedSaw this one early, left some comments.
Comment #7
pooja_sharma commentedThank for reviewing, working on it
Comment #8
pooja_sharma commentedAddressed the feedback, left one comment on MR. PLease review, moving NR.
Comment #9
smustgrave commentedResponded to comment
Comment #10
smustgrave commentedWill also need change record.
Comment #11
pooja_sharma commentedThanks for reviewing. working on the feedback.
Comment #12
quietone commentedNice to work on issues in the Modernization effort. Thanks!
This is changing the UI so adding Usability tag. As a new form this should have a Usability review as well, so adding that tag. And screenshots available from the issue summary.
Comment #13
pooja_sharma commentedTried to address feedback, Added: validation constrains, change records, screenshots in IS.
MR is mergeable, however there is validation config warning that shows this is 'field.formatter.settings.title', added which is correct , so it seems it is just message not any error message displaying here. PLease review, moving NR.
Comment #14
pooja_sharma commentedComment #15
smustgrave commentedCode wise don't see anything but leave in review for usability
Comment #16
mradcliffeCould a site builder end up creating a situation where they set the sub title to use h2 and then the hierarchy no longer matches between teaser and page views?
- Page
- h1: Node Title via page-title
- h2: Sub title
- Teaser
- h1: Page title
- h2: Node title
- h2: Sub title
Comment #17
pooja_sharma commented- Page
- h1: Node Title via page-title
- h2: Sub title
- Teaser
- h1: Page title
- h2: Node title
- h2: Sub title or h3: Sub title (whatever selected in tag of title formatter in specific form mode like here teaser, 'll render on FE)
Yes I have verified it is possible, correct me if I 'm missing anything.
Comment #18
sheetal.pathak commentedI am not able to reproduce issue , not getting Title dropdown
Steps to followed
1. Added Plain text filed in Article.
2. Configured in manage display , not getting title Drop down in Format column fort "Title".
3. Adding screenshot for reference.
Comment #19
sokru commented+1 for adding this feature, so it would make easier to land the parent issue.
Left suggestion also to add H6 -level element.
I assume #18 was missing a cache clearance.
Comment #20
pooja_sharma commentedh6 tag by mistaken missed added back, Please review moving NR
Comment #21
pooja_sharma commentedComment #22
benjifisherUsability review
We discussed this issue at #3472580: Drupal Usability Meeting 2024-09-13. That issue has a link to a recording of the meeting.
For the record, the attendees at the usability meeting were @AaronMcHale, @benjifisher, @rkoller, @shaal, @simohell, @worldlinemine, and @zetagraph.
We like the idea of giving site builders more flexibility in how plain-text fields are displayed. Once the parent issue is done, it will be much easier for site builders to create a consistent heading hierarchy, which will be a big a11y improvement.
Our main recommendation is that we improve the existing (default) formatter for plain-text fields instead of adding a new one. That is, add the select list of tags to the existing formatter. I read the comments on this issue and on the parent issue, and I did not see any discussion of this option. Is there any reason to have a separate formatter?
For backwards compatibility, we will have to add an option (for example,
- none -) and make that the default.A minor advantage of improving the existing formatter is that we do not have to decide how to name (or label) the new one. Naming things is hard, and it is generally best to name things after what they do. The proposed label in this issue is "Title", which is how you expect to use it rather than a description of what it does.
Our other recommendations are
Once this issue is implemented, people are likely to ask for additional options:
<p>and<code>and so on. This seems like a good idea for a follow-up issue: either a hook that modules can implement or some global configuration that site builders can choose in order to change the list of available tags.If you want more feedback from the usability team, a good way to reach out is in the #ux channel in Slack.
Comment #23
pooja_sharma commentedThanks for reviewing it, I agree , we can simply enhance the existing formatter rather than introducing new one. In proposed solution section written
so I thought need to create new one.
I believe along with one mentioned feedback need upgrade path as well , as we are enhancing existing formatter, feel free to add anything that needs to be taken care along with these changes.
Comment #24
mortona2k commentedI would not mind being able to select a tag for the plain text formatter to do this. But what about setting a class, or settings for field/wrapper elements? I am thinking of the Fences module.
Comment #25
benjifisher@poojah_sharma:
If the default "none" option is represented in the database as no entry (as opposed to an entry of "none") then I am not sure we need an upgrade path. At least, if "upgrade path" means an update (or post-update) function.
Any issue on d.o is a cooperative effort. We often think of better solutions before an issue is fixed, so do not assume that the current proposed resolution is the final one. If you have a better idea, then suggest it. Since we are changing the resolution, we should update that section of the issue summary. I am adding the tag for that. I probably should have done that with my previous comment.
@mortona2k:
I am also a fan of the Fences module, and we looked at it during the usability meeting. But let's not expand the scope of this issue to include everything that Fences provides. The current scope is enough to advance the parent issue. If you want all the features of Fences, then install it, and if you think that should be part of core then open a new issue to discuss it.
In fact, once the parent issue is fixed, you should be able to install the Fences module and then add CSS classes to your node titles (and not just nodes).
Comment #26
pooja_sharma commentedComment #27
pooja_sharma commented@benjifisher, I missed the point, like better solution is to add same tag in existing formatter instead of creating new one, thanks for the feedback, 'll try to keep address these points as well.
Try to addressed the requested changes , update issue summary as well. as we have used '-None- as by default so when I try save entity from "manage form" page then is no any error encountered , I guess no need to add upgrade path as well.
PLease review, moving NR.
Comment #28
pooja_sharma commentedComment #29
pooja_sharma commentedComment #30
adamps commentedI am happy with the idea to extend the existing formatter rather than create a new one. In the manage display module we can create a migration from TitleFormatter.
The new code looks good to me thanks.
Comment #31
pooja_sharma commentedAdded test coverage in existing kernel test instead of creating new functional test considering performance perspective.
Please review, moving NR.
Comment #32
pooja_sharma commentedResolving conflicts, verifying functionality
Comment #33
pooja_sharma commentedComment #34
pooja_sharma commentedResolved MR conflicts, functionality seems working fine.
Please review , moving NR.
Comment #35
manibharathi ezhimalai ravi commentedHi,



Changes has been verified in the issue fork branch. working has expected to the branch.
Before Branch:
After: Branch:
But the patch 9341.patch is failing in the Drupal 11.x branch. Please find the screenshot for the more understanding.

Comment #36
sokru commentedI think all threads should be resolved now.
Comment #41
larowlanIssue credits, including those from UX meeting
Crediting @manibharathi ezhimalai ravi for manual testing
Comment #42
larowlanThis is a great feature. We need to add an upgrade path.
This should take the form of a post update hook that makes use of the config entity updater.
There should also be a test that asserts the value isn't set before running update, and then checking it is set.
There's a good example of a similar update hook (also for entity view displays) here https://git.drupalcode.org/project/drupal/-/merge_requests/10002/diffs#2...
This MR also contains a good example of an upgrade path test - https://git.drupalcode.org/project/drupal/-/merge_requests/10002/diffs#2...
Unfortunately it doesn't look like there are any instances of this formatter in use in the standard profile, so that means you will have to create a new database dump/fixture file.
\Drupal\Tests\views\Functional\Update\EntityArgumentUpdateTestin core has an example of how to add additional test fixtures to the default standard dump.The docs have more information on how you can do that - https://www.drupal.org/docs/drupal-apis/update-api/writing-automated-upd...
Comment #43
pooja_sharma commented@larowlan, Thanks for reviewing , working on it
Comment #44
andypostComment #45
mradcliffeI fixed a typo and changed the resolution from being a question to a statement in the proposed resolution that made it difficult for me to understand without reading the code.