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

Comments

bigscotia10 created an issue. See original summary.

thtas’s picture

Thanks 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?

bigscotia10’s picture

Hey, 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.

thtas’s picture

Status: Active » Closed (works as designed)

The 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.

slv_’s picture

Version: » 8.x-1.x-dev
Status: Closed (works as designed) » Needs review
StatusFileSize
new916 bytes

Hi 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!

slv_’s picture

Err, 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.

  • thtas authored d16e20a on 8.x-1.x
    Issue #2935718 by slv_, thtas: Node title field label
    
thtas’s picture

Status: Needs review » Fixed

Nice solution. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.