Exclude Node Title preference on an entity (like a Content Type) is overwritten if the view mode has a Layout Builder configuration which contains the Title field, leading to the Title field being shown twice (once for the default, supposed to be overwritten title; and once for the custom field).

To reproduce:

1. Configure Exclude Node Title for the content type and the associated display (in this example, Teaser).
2. Configure the Content Type display mode for Teaser to use Layout Builder, and add the Title field to a Section within LB.
3. Save the Layout.
4. Ta-da! You've worked around Exclude Node Title.

Command icon 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

Webbeh created an issue. See original summary.

Webbeh’s picture

Title: Title exclusion is overridden if Layout Builder configuration has title field » Title exclusion is overridden if Layout Builder layout has title field
bigjim’s picture

I can confirm this issue, sadly I don't have a patch to fix :(

bigjim’s picture

Okay, though I can re-create the issue I just realized it's only when the "Link to the Content" box is checked on the title block in LB

tonytheferg’s picture

I can confirm.

Christopher Riley’s picture

This is kind of a deal breaker. It would be nice if it was addressed.

jrochate’s picture

I've tried to remove the "Link to the Content" checkbox, but still the title still appears when using LB

cbwiedel’s picture

Also an issue with Display Suite, please fix

mav_fly’s picture

I have the same problem

stevenjay’s picture

I ran into this problem and was able to solve it by adding the following line of code to the preprocessTitle procedure in /src/Plugin/DsField/Node/ExcludeNodeTitleManager.php

After line 265: $vars['label'][0]['#context']['value'] = '';
Added: $vars['label'][0]['#title']['#context']['value'] = '';

Hope this helps fix the issue

  /**
   * {@inheritdoc}
   */
  public function preprocessTitle(&$vars, $node, $view_mode) {
    if ($this->isTitleExcluded($node, $view_mode)) {
      $node_info = $this->getNodeInfo($node);
      $node_type = $node_info['node_type'];

      switch ($view_mode) {
        case 'nodeform':
          $node_types = $this->bundleInfo->getBundleInfo('node');
          if (!empty($vars['head_title'])) {
            $vars['head_title']['title'] = new TranslatableMarkup('Edit @nodetype', ['@nodetype' => $node_types[$node_type]['label']]);
          }
          elseif (!empty($vars['title'])) {
            $vars['title'] = new TranslatableMarkup('Edit @nodetype', ['@nodetype' => $node_types[$node_type]['label']]);
          }
          break;

        default:
          if (!empty($vars['title'])) {
            if ($this->isRenderHidden()) {
              $vars['title_attributes']['class'][] = 'hidden';
            }
            elseif ($this->isRenderRemove()) {
              $vars['title'] = new HtmlEscapedText('');
            }
          }
          if (!empty($vars['page']) && is_array($vars['page'])) {
            if ($this->isRenderHidden()) {
              $vars['page']['#attributes']['class'][] = 'hidden';
            }
            elseif ($this->isRenderRemove()) {
              $vars['page']['#title'] = new HtmlEscapedText('');
            }
          }
          if (!empty($vars['elements']) && is_array($vars['elements'])) {
            if ($this->isRenderHidden()) {
              $vars['elements']['#attributes']['class'][] = 'hidden';
            }
            elseif ($this->isRenderRemove()) {
              $vars['elements']['#title'] = new HtmlEscapedText('');
            }
          }
          if (!empty($vars['label']) && is_array($vars['elements'])) {
            if ($this->isRenderHidden()) {
              $vars['label']['#attributes']['class'][] = 'hidden';
            }
            elseif ($this->isRenderRemove()) {
              $vars['label']['#title'] = new HtmlEscapedText('');
              $vars['label']['#markup'] = new HtmlEscapedText('');
              $vars['label'][0]['#context']['value'] = '';
              $vars['label'][0]['#title']['#context']['value'] = '';
            }
          }
          break;

      }
    }

    return $this;
  }

Sahana _N made their first commit to this issue’s fork.

sahana _n’s picture

Status: Active » Needs review

Created a MR please review.

leducdubleuet’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm the patch is working properly! Thank you!

sea2709’s picture

I confirm the MR fixed the issue when the title is showing twice on my end!

_kash_ made their first commit to this issue’s fork.

_kash_’s picture

The patch helped. But I still had issues with the title showing up on pages using layout builder when using a display mode other than default. Unsetting the label[0] element fixed everything for me. I pushed up a change to the issue fork.

  • smustgrave committed 50f460a2 on 2.0.x
    Issue #3160620 by sahana _n, _kash_, Webbeh: Title exclusion is...
smustgrave’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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