Title exclusion is overridden if Layout Builder layout has title field

Created on 21 July 2020, over 4 years ago
Updated 19 September 2024, about 2 months ago

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.

๐Ÿ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States Webbeh Georgia, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mettasoul

    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;
      }
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Sahana _N

    Sahana _N โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Sahana _N

    Created a MR please review.

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada leducdubleuet Chicoutimi QC

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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States sea2709 Texas

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

  • First commit to issue fork.
  • The patch helped. But I still had issues with the title showing up on pages using layout builder. Unsetting the label[0] element fixed everything for me. I pushed up a change to the issue fork.

Production build 0.71.5 2024