Hey there -
Just testing out your module. Curious.. any idea why the node form title doesn't display the field label along with the field data when "read only" is selected?
Thanks,
Chris
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2935718-node_title_field_label_missing-6.patch | 948 bytes | slv_ |
| #5 | 2935718-node_title_field_label_missing-5.patch | 916 bytes | slv_ |
Comments
Comment #2
thtas commentedThanks for testing out the module.
You should be able to select to hide or show the field label to go along with the read-only version of the field in the form widget settings.
There might be a problem if that selection isn't available - what's your setup?
Comment #3
bigscotia10 commentedHey, thanks for having a look!
Yeah, it looks like it works for all the fields, except the node title field label.
On D8.4 - I've got a node with 6 fields. 4 of the fields are set to "read only", including the title field. All set to display label inline. It looks like all fields show the label and "read only" field value except the node title. The node title field value is there, just not the label.
To reproduce, if you have the module installed:
Change the node form field title to "read only" and select the option to display the label "above" or "inline". It shows the field value, but not the label.
Comment #4
thtas commentedThe reason the title field behaves this way is because Drupal core has template overrides for this specific field which exclude the field label.
see
core/modules/node/templates/field--node--title.html.twig
core/themes/classy/templates/field/field--node--title.html.twig
core/themes/stable/templates/field/field--node--title.html.twig
There is no {{ label }} in these templates.
So if you want the title label to show up it needs to be using a different field template.
I guess the simplest way to do it would be to override field--node--title.html.twig in your theme and replace the contents of the template with the default field template from core/modules/system/templates/field.html.twig
I hope that answers your question.
Comment #5
slv_ commentedHi there, thanks for this module @thtas.
I'm reopening as this is clearly a bug: The module still shows the Label options dropdown on the form mode settings, despite ignoring them (even if the reason is that core overrides the template, the end UX is that the UI says one thing, and the outcome is different).
There's a workaround without forcing uses to add a custom template, to add the expected behavior to this. Attaching patch for it, I hope it helps!
Comment #6
slv_ commentedErr, last patch might not work in all cases as core overrides might come after it. Re-rolled patch using `theme_suggestions_alter` hook instead, to make sure the template enforcement comes after core's.
Comment #8
thtas commentedNice solution. Thanks!