Allow to edit page title when using Layout Builder variant

Created on 13 October 2020, almost 5 years ago
Updated 16 April 2024, over 1 year ago

Problem/Motivation

Title of page variant of type Block Page can be edited on the General tab. The same is not possible when using page variant of layout builder type.

Steps to reproduce

  • Create a new page variant of Layout Builder type
  • Go to General tab and on Label field can be edited.

Proposed resolution

Variant types Block page and Layout builder should allow editing of page title after variant creation.

✨ Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡¨πŸ‡ΏCzech Republic milos.kroulik

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

Comments & Activities

Not all content is available!

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

  • πŸ‡¨πŸ‡¦Canada liquidcms

    Patch applies to latest dev and mostly works. The "title" is being set but the metatitle is still showing as the title used to create the page.. which doesn't seem to be editable.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Could someone please turn this into a MR instead of patches?

  • First commit to issue fork.
  • @goz opened merge request.
  • πŸ‡ΏπŸ‡¦South Africa daniel bornman

    The patch works for me but I ran into a bit of an edge case here - the current LayoutBuilderDisplayVariant::build() implementation as in the patch / pull request builds blocks in the order they were added, not their weight as Drupal\layout_builder\Section::toRenderArray() would.

    Leveraging Drupal\layout_builder\Section::getComponentsByRegion() to sort the blocks by weight as in Drupal\layout_builder\Section::toRenderArray(), fixes the issue:

    /**
     * {@inheritdoc}
     */
    public function build() {
      $build = [];
      $contexts = $this->getContexts();
      $in_preview = FALSE;
    
      /** @var \Drupal\layout_builder\Section $section */
      foreach ($this->getSections() as $delta => $section) {
        $layout_definition = $section->getLayout()->getPluginDefinition();
        foreach ($layout_definition->getRegionNames() as $region) {
          foreach ($section->getComponentsByRegion($region) as $component) {
            if ($block = $component->toRenderArray($contexts, $in_preview)) {
              if ($this->configuration['title_type'] === 'block' && $this->configuration['title_from_block'] === $uuid) {
                $build['#title'] = $this->getBlockTitle($block);
                $block['#configuration']['label_display'] = 0;
              }
    
              $regions[$component->getRegion()][$component->getUuid()] = $block;
            }
          }
        }
        $build[$delta] = $section->getLayout()->build($regions);
      }
    
      if ($this->configuration['title_type'] === 'manual') {
        $build['#title'] = $this->renderManualPageTitle($this->configuration['manual_title']);
      }
    
      return $build;
    }
    
  • πŸ‡ΏπŸ‡¦South Africa daniel bornman

    I'm attaching a patch with the change I described above, for reference. It adjusts the build order by using Drupal\layout_builder\Section::getComponentsByRegion(), aligning with Drupal\layout_builder\Section::toRenderArray() behavior and fixing the edge case with block weights.

Production build 0.71.5 2024