Go to /admin/modules and enable Layout Builder module.
Go to /admin/structure/types/manage/article/display and enable tick Use Layout Builder checkbox.

On "/admin/structure/types/manage/article/display-layout/default" if you place the "Page Title" block there will not be Placeholder Text.
Also when you view the Article the page title is empty.

Comments

tedbow created an issue. See original summary.

tedbow’s picture

Issue summary: View changes
StatusFileSize
new113.07 KB
kducharm’s picture

Assigned: Unassigned » kducharm
kducharm’s picture

Status: Active » Needs review
StatusFileSize
new4.77 KB

Modified page title block to use route to populate title during build(), added check in Section rendering loop to change title text to a placeholder. There is some question on what routes should be used to check against so this only appears in layout builder admin, or a better way to identify when the placeholder should be shown.

Created with @tedbow, @geinosky, and @lokapujya

geinosky’s picture

I concur.

kducharm’s picture

runeasgar’s picture

Testing latest patch.

runeasgar’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new39.98 KB
  1. Enabled Field Layout, Layout Builder, Layout Discovery modules (not sure what all I need, but that seems comprehensive).
  2. Navigated to /admin/structure/types/manage/article/display-layout/default .
  3. Added page title, confirmed undesirable behavior.
  4. Canceled layout editing.
  5. Installed patch: $ curl -l https://www.drupal.org/files/issues/2018-04-13/page-title-block-2959962-4.patch | git apply -v. Succeeded with no errors or warnings.
  6. Re-navigated to /admin/structure/types/manage/article/display-layout/default .
  7. Added page title, confirmed there is now a placeholder. See screenshot below.

Moving to RTBC.

tedbow’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

@runeasgar thanks for the manual testing!

Settings back to "Needs work" because the patch still needs automated test classes to confirm the fix.

lokapujya’s picture

How should this be tested? A test that checks all Core provided blocks in the layout builder that should have a placeholder?

runeasgar’s picture

@tedbow, given that it's unclear to me when programmatic tests are needed, should I still be moving things to RTBC when I manually test them? I figure if I don't move things to RTBC and they don't need programmatic tests, then someone else has to come along, notice that, and move it to RTBC (which slows the process down for those issues).

Happy to follow whatever process is recommended.

lokapujya’s picture

@runeasgar, Thank You for testing the issue! Any bugfix in Drupal core needs an automated test. See: Drupal core gates. So, instead of marking RTBC, add the "Needs Tests" tag.

tedbow’s picture

@runeasgar yep @lokapujya explained it well.

For this bug we will need functional tests for the page title block that include

  1. When placed on /admin/structure/types/manage/article/display-layout/default a placeholder value should show
  2. When place on /node/[nid]/layout a placeholder value should show
  3. When viewed on node/[nid] the page title should show
kducharm’s picture

Assigned: kducharm » Unassigned
runeasgar’s picture

Some day I'll need to learn to write said tests ^_^ seems like low-hanging fruit.

tedbow’s picture

@runeasgar it's not super hard, especially functional tests.

If you are interested in looking at an example:
\Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testLayoutBuilderUi
\Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testLayoutBuilderUiFullViewMode
Probably have all the logic that is needed to add the Page title block in a test and confirm that it shows up correct.

You would write a new test method on \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest called testPageTitleBlock(that is where I would start anyways.

runeasgar’s picture

Thanks! I will take a look when I have some time to sit down and learn.

lokapujya’s picture

StatusFileSize
new1.87 KB
new6.63 KB
new1.87 KB

Started a test.

lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Let me actually run this and see what happens.

tim.plunkett’s picture

Nice test!

  1. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
    @@ -16,14 +21,75 @@
        * @var string|array
        */
    -  protected $title = '';
    +  protected $title = NULL;
    +
    

    The @var needs updating

  2. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
    @@ -16,14 +21,75 @@
    +  protected $title = NULL;
    ...
    +  protected $titleResolver = NULL;
    ...
    +  protected $request = NULL;
    ...
    +  protected $routeMatch;
    

    = NULL is redundant, please remove

  3. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
    @@ -16,14 +21,75 @@
    +   * @var null|TitleResolver $titleResolver
    ...
    +   * @var null|RequestStack
    ...
    +   * @var \Drupal\Core\Routing\RouteMatchInterface
    

    These should use the fully-qualified class name, not include the variable name, and should not have the |null (if they're set in the constructor, which they are)

  4. +++ b/core/modules/layout_builder/src/Section.php
    @@ -78,6 +79,15 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
    +        // Add placeholder for page_title_block in layout_builder admin.
    +        if (isset($output['#plugin_id']) && $output['#plugin_id'] === 'page_title_block') {
    +          $route = \Drupal::routeMatch();
    +          // @todo Many layout routes are run from admin, this may be too broad.
    +          if (strpos($route->getRouteName(), 'layout_builder') !== FALSE) {
    +            // Change title to a placeholder.
    +            $output['content']['#title'] = new TranslatableMarkup('@label - Placeholder for the Page Title Block', ['@label' => $output['#configuration']['label']]);
    +          }
    +        }
    

    Hmmm. I really don't like special-casing this code here. If it must live outside the page title block, can you move this to an event subscriber for the LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY event?

kducharm’s picture

@tim.plunkett for this:
if (strpos($route->getRouteName(), 'layout_builder') !== FALSE) {

I saw you mentioned in slack that if ($route_match->getRouteObject()->getOption('_layout_builder')) { may be a better option, should we do that here?

The last submitted patch, 19: 2959962-19-test-only.patch, failed testing. View results

tim.plunkett’s picture

Yes definitely would be better. But my point remains, this is not the place to be inserting per-block logic.

Also, at the Nashville sprint I thought it was suggested that this could use a lazy builder and placeholder, and then it could live inside the block itself. Was that ever explored?

johnwebdev’s picture

Assigned: Unassigned » johnwebdev
johnwebdev’s picture

StatusFileSize
new8.35 KB
new1.87 KB
new4.76 KB

Adressed #21.

Not entirely sure if the PageTitleSubscriber should belong in Core like in this uploaded patch, or in layout_builder, ... or somewhere else.

The last submitted patch, 26: 2959962-26.patch, failed testing. View results

johnwebdev’s picture

Assigned: johnwebdev » Unassigned

The last submitted patch, 26: 2959962-26.patch, failed testing. View results

johnwebdev’s picture

StatusFileSize
new8.52 KB
new5.54 KB
new1.87 KB

Alright, looks like testbot did answer that question for me. Here it is in layout_builder module instead.

The last submitted patch, 26: 2959962-26-test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 30: 2959962-27-test-only.patch, failed testing. View results

tim.plunkett’s picture

Oh this makes me feel so much better to see as an event! It will give people an example of how to manipulate block output specifically for Layout Builder.
We might eventually want to codify this better with an event base class... But that can be for another time

  1. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
    @@ -44,6 +110,10 @@ public function defaultConfiguration() {
    +    // Page Title may not already be set before build, populate via route.
    +    if ($this->title === NULL) {
    +      $this->title = $this->titleResolver->getTitle($this->request->getCurrentRequest(), $this->routeMatch->getRouteObject());
    +    }
    

    I'm not 100% sure how this relates to the placeholder change. And it doesn't seem to have its own test coverage

  2. +++ b/core/modules/layout_builder/src/EventSubscriber/PageTitleSubscriber.php
    @@ -0,0 +1,70 @@
    +    $block = $event->getPlugin();
    ...
    +    if (isset($build['#plugin_id']) && $build['#plugin_id'] === 'page_title_block') {
    

    $build isn't super reliable, this could be $block->getPluginId() === 'page_title_block'

  3. +++ b/core/modules/layout_builder/src/EventSubscriber/PageTitleSubscriber.php
    @@ -0,0 +1,70 @@
    +        $build['content']['#title'] = new TranslatableMarkup('@label - Placeholder for the Page Title Block', ['@label' => $build['#configuration']['label']]);
    
    +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -319,4 +319,41 @@ public function testLayoutBuilderUiFullViewMode() {
    +    $assert_session->pageTextContains('Page title - Placeholder for the Page Title Block');
    

    The "@label - Placeholder..." seems redundant.

    Instead I'd suggest 'Placeholder for the "@admin_label" block' with @admin_label corresponding to $block->getPluginDefinition()['admin_label']
    Also, should it be #title or #markup?

johnwebdev’s picture

StatusFileSize
new8.48 KB
new1.86 KB
new2.06 KB

1. It kinda does. Actually this issue solves two bugs (I just realised myself), because Page title does not render when placed on LB UI without this part of the code.
So, this part of the test kinda verifies this code change, but not very explicitly:

$assert_session->elementExists('css', '.block-page-title-block');

So perhaps it deserves to be solved in another issue which this one may be blocked on, or we write a test for it here, or we can extract that part of the code and let the page title subscriber actually set the title in the context for LB. What do you think?

The Page title block title is set by BlockPageVariant when placed on a region through Block UIs.

Edit: Looks like these problems already been adressed in this issue: https://www.drupal.org/project/drupal/issues/2938129

2. Fixed

3. Fixed

It should be #title, since that is the variable used by the page_title render element.

johnwebdev’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 34: 2959962-34-test-only.patch, failed testing. View results

johnwebdev’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

+++ b/core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
@@ -16,14 +21,75 @@
-class PageTitleBlock extends BlockBase implements TitleBlockPluginInterface {
+class PageTitleBlock extends BlockBase implements TitleBlockPluginInterface, ContainerFactoryPluginInterface {

I'd rather move these changes to #2938129: PageTitle block is non-functional when not handled directly by \Drupal\block\Plugin\DisplayVariant\BlockPageVariant (good find, I knew there was an issue but couldn't locate it)

The interdiff changes are great.

johnwebdev’s picture

StatusFileSize
new4.98 KB
new3.3 KB

Alright, I reverted changes made in PageTitleBlock. Tests remains the same, so no test only reupload.

tim.plunkett’s picture

Nice, this looks really great. One more round of feedback from me.

  1. +++ b/core/modules/layout_builder/src/EventSubscriber/PageTitleSubscriber.php
    @@ -0,0 +1,70 @@
    +    $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = ['onBuildRender', 90];
    

    Why the 90 priority? If it needs to be something other than 0, this needs a comment explaining it.

  2. +++ b/core/modules/layout_builder/src/EventSubscriber/PageTitleSubscriber.php
    @@ -0,0 +1,70 @@
    +    $build = $event->getBuild();
    ...
    +        $build['content']['#title'] = new TranslatableMarkup('Placeholder for the "@admin_label" block', ['@admin_label' => $block->getPluginDefinition()['admin_label']]);
    +        $event->setBuild($build);
    

    I know you said that the existing build needs this to be #title. But I would expect that instead of retrieving the existing build, that this could simply set build to a new render array. And if not, the getBuild could move inside the if()

  3. +++ b/core/modules/layout_builder/src/EventSubscriber/PageTitleSubscriber.php
    @@ -0,0 +1,70 @@
    +    if ($block->getPluginId() === 'page_title_block') {
    +      if ($this->routeMatch->getRouteObject()->getOption('_layout_builder')) {
    

    Might as well one-line this

johnwebdev’s picture

StatusFileSize
new4.96 KB
new1.59 KB

#40.1 Fixed.

#40.2 Moved getBuild() within if().

#40.3 Fixed.

tim.plunkett’s picture

We discussed the other part of #41.2, and the current approach is needed to keep the rest of the block working.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

If that passes tests (only reason it wouldn't is the priority change), then I think this is done!

footwearboss’s picture

Enabled Field Layout, Layout Builder, Layout Discovery modules (not sure what all I need, but that seems comprehensive).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 41: 2959962-41.patch, failed testing. View results

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new4.96 KB

Keeping this up to date.

runeasgar’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new38.91 KB
  1. I've already reproduced this issue previously on 8.6.x, so skipping straight to testing the fix.
  2. Applying patch: curl -l https://www.drupal.org/files/issues/2018-05-01/2959962-46.patch | git apply -v
  3. Applied clean.
  4. Enabling Field Layout, Layout Builder, Layout Discovery modules.
  5. Navigated to /admin/structure/types/manage/article/display-layout/default
  6. Added page title: confirmed new, desirable behavior. Screenshot below.

However, there is an inconsistency.. sort of. Look at the comments placeholder.. it's much more verbose - I know it's for comments. But, "darithijacrogiuucloswojuuaprahinispeliw"? I realize this is some random generation thing, meant to help ensure your content will fit where you're putting it.. but this seems really confusing for an end-user.

How would I know this is the title if I was another end-user coming in to look at this later? I'd have to click the pencil, then configure, in order to see that. Seems pretty bad.

Regardless, setting as RTBC. It's better than the current behavior.

lokapujya’s picture

Page title does not render when placed on LB UI when javascript is enabled; The test passes because it doesn't use AJAX. Another patch (event subscriber?) is needed in order to fix the LB UI.

@runeasgar
This random text is the page title override.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
@@ -349,4 +349,41 @@ public function testLayoutBuilderChooseBlocksAlter() {
+    $assert_session->elementExists('css', '.block-page-title-block');

Yeah but this is not doing the expected thing of actually displaying the page title. I've tested this manually and it's empty on node/1 even though the page title is the node title.

Also as #48 points out with Javascript enabled the UI doesn't really work either.

Am I missing something?

johnwebdev’s picture

@alexpott

See #34 and #38. This issue only intends to solve the placeholder on LB UI for the Page title.

alexpott’s picture

Okay well we still have the problem with real-life javascript enabled usage.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

savkaviktor16@gmail.com’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.94 KB

Re-rolled against 8.7.x

dmsmidt’s picture

Manually tested this and it works as expected.

Concerning the real-life JavaScript issue mentioned in #49/#51, this also happens for the core Tabs block.
After refreshing the page the block content is visible until you start rearranging blocks.
If we can agree this is something for a follow up, I'm fine with RTBC-ing this again.

pazhyn’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +DrupalNorth2018
StatusFileSize
new502.98 KB

Applied manually #54 and it shows the placeholder only after page refreshing. Once you add the block - no placeholder is shown.
Attaching screenshot.

tedbow’s picture

Status: Needs work » Needs review
StatusFileSize
new5.13 KB

Need another re-roll

tim.plunkett’s picture

Status: Needs review » Postponed

Let's postpone this on the new proposed block placeholder API: #2992410: Provide placeholders for empty blocks (for example, an empty Views listing)

tim.plunkett’s picture

Status: Postponed » Needs review
StatusFileSize
new2.69 KB
new3.77 KB

New approach

Status: Needs review » Needs work

The last submitted patch, 59: 2959962-pagetitle-59.patch, failed testing. View results

tedbow’s picture

The fail in #59 is in an seemingly unrelated test method \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testNoShortcutLink()

The problem is that test method is using the router_test test module to test that

// Verify that the shortcut link appears on routing only pages.

But that test route actually has no title. That is not what that test is actually intending to test.
So it is actually testing that \shortcut_preprocess_page_title will be called for a page that has no title. It seems like that is wrong.

For the shortcut case in particular it is testing that add shortcut link is on this page with no title.
but if you actually tested this and actually clicked the add shortcut star in seven theme it would make a shortcut with no title. it would then show up in the shortcut list as a blank line that you could actually click but it would just look like a blank line.

I think we could either

  1. update the route in router_test.routing.yml to have titles. I don't having no titles is actually anything that is actually being intentionally anywhere. Only 2 tests use this test module.
  2. Or just make a test module directly for the shortcut module.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

Status: Needs work » Postponed (maintainer needs more info)

So this block now no longer exists in the UI? Is that right? So do we postpone this on #2938129: PageTitle block is non-functional when not handled directly by \Drupal\block\Plugin\DisplayVariant\BlockPageVariant ?

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Issue tags: +Bug Smash Initiative

Yea I think this can be marked a duplicate for #2938129: PageTitle block is non-functional when not handled directly by \Drupal\block\Plugin\DisplayVariant\BlockPageVariant believe when that lands this will be fixed. Am leaving all credit too for all the work.