Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Cook created an issue. See original summary.

John Cook’s picture

FileSize
560 bytes

I've found that I can get the title to display if I change core/modules/system/src/Controller/BatchController.php::batchPage() to return:

$html = [
  '#type' => 'html',
  'page' => $output,
];
return $html;

But this includes a nested version of the page - complete with <head> tags and javaScript includes.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

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

eelkeblok’s picture

This seems to have been the subject of another issue before. #2282035: Title not shown during a batch operation

th_tushar’s picture

Issue tags: +Vienna2017, +Novice
hctom’s picture

Assigned: Unassigned » hctom

I'll give this a try ;)

th_tushar’s picture

Assigned: hctom » Unassigned

@hctom,

Just un-assigning the issue. But, you can continue working on the issue though. :)

Thanks!!

hctom’s picture

Status: Active » Needs review
FileSize
819 bytes

Okay, I digged into this issue, and found out, that the header region is not set in the BatchController class. So when this is empty, no header content will be rendered. See HtmlRenderer class (lines 262 and following):

    // $page is now fully built. Find all non-empty page regions, and add a
    // theme wrapper function that allows them to be consistently themed.
    $regions = \Drupal::theme()->getActiveTheme()->getRegions();
    foreach ($regions as $region) {
      if (!empty($page[$region])) {
        $page[$region]['#theme_wrappers'][] = 'region';
        $page[$region]['#region'] = $region;
      }
    }

As a fix, I now injected a page_title render element into the header region (if a title is present), which is then rendered at the top of the page. I am not really sure, if this is more like a hacky solution, or if this is the way to go.

So please review the patch attached and feel free to provide feedback/customizations.

@th_tushar: Why did you un-assign the issue? Fortunately nobody else was also trying to fix this the same time...

rivimey’s picture

I have reviewed the patch and it seems good. I would suggest the attached change to it as a code-quality improvement however, which simplifies title processing and makes it clear that the same value is being used for page title and header.

The last submitted patch, 10: batch_missing_title_on-2744663-9.patch, failed testing. View results

John Cook’s picture

Thank you @hctom and @rivimey for the patches.

There's a couple of tweaks that are needed.

`$title = isset($output['#title']) ? $output['#title'] : NULL;`
This could introduce a problem as a value in the render array could be set to null. Maybe an empty string would be better.

`// Also inject title as a page header (if available).`
Change to: `// Place the title in the header region.`

jholding’s picture

I'm at DrupalCon Vienna, first time sprinter, giving this one a go :)

jholding’s picture

Status: Needs review » Needs work

The last submitted patch, 15: batch_missing_title_on-2744663-15.patch, failed testing. View results

John Cook’s picture

Issue summary: View changes

Updated the summary.

jholding’s picture

Re-done patch due diff against wrong branch.

xjm’s picture

Issue tags: +Needs tests

Thanks everyone for the work so far here! The screenshots also help explain the issue.

I was just looking into the possibility of adding automated test coverage for this bug. It might be tricky to test during the batch test run, but we do have tests for the start and the end in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php. Is the page title gone the whole time? Can we add test assertions that fail in HEAD, but pass when combined with our fix here?

It might also be that the title is only missing during the middle of the batch running, but let's check.

jholding’s picture

John Cook’s picture

An existing test has been updated by @jholding to test that the title appears on screen as requested by @xjm.

`batch_missing_title_on-2744663-20-test-only.patch` is also an interdiff of `batch_missing_title_on-2744663-18.patch` and `batch_missing_title_on-2744663-20.patch`, and as such is designed to fail on before this issue is committed.

mahalingam_cs’s picture

Applied patch from #20 and it worked as expected. The titile is appearing for the batch properly. Attached the before and after screenshot.

The last submitted patch, 20: batch_missing_title_on-2744663-20-test-only.patch, failed testing. View results

John Cook’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This implementation, originally by @hctom and improved by @rivimey and @jholding has now been manually tested by @mahalingam_cs.

I asked @andrewmacpherson to look over the implementation from an a11y standpoint and he said that it was OK.

@jholding then altered the title checking test as requested by @xjm. The test shows that the title is missing in 8.4-rc2 and that this patch, batch_missing_title_on-2744663-20.patch fixes the issue.

With this I've set this issue to RTBC.

I've also changed the issue summary to include the images be @mahalingam_cs are better than the previous ones.

John Cook’s picture

Issue tags: -Novice, -Needs tests
John Cook’s picture

eelkeblok’s picture

Awesome to see this getting fixed. One of those weird little things you're not even sure is an issue but you keep wondering the same thing every time you see it. Awesome work everyone!

gambry’s picture

Status: Reviewed & tested by the community » Needs review

Must be mentioned test on #20 is altering an existing testBatchProgressPageTitle() test, which doc block reads: "Tests that the batch API progress page shows the title correctly."

That bit was introduced on #2282035: Title not shown during a batch operation, but to me it doesn't do what it says. It tests the title can be resolved, but not that the title shows correctly (in fact we have the bug this issue is trying to fix :) ).
Do we understand the reasons why that has been done? Is it still relevant?
If relevant, should we tidy up and maybe split the tests in 2, one checking the title can be resolved and one checking the title shows up correctly?
If not, should we remove the not-relevant bit and keeping only last test?

#20 looks like testing only the initial iteration ($this->maximumMetaRefreshCount = 0). I'm not 100% confident with Batch API but is it worth checking title is still there while batch is in progress, i.e. $this->maximumMetaRefreshCount = 1?

John Cook’s picture

Status: Needs review » Reviewed & tested by the community

@gambry, the new code does do what the test intends to achieve so I think this is the correct place of it. It may be worth getting some feedback from hussainweb, RavindraSingh, joachim, or alexpott about what the original test was doing but as it done two years ago there might not be any information forthcoming.

Once the batch is running, the title does not get updated so only needs to be run on the initial load. In fact, due to how the batch system works, it might never get to $this->maximumMetaRefreshCount = 1 depending on the resources available when the tests are run. This might lead to failures as this state can not be guaranteed but the test script expects it.

I'm going to set this back to RTBC. It is better to have the issue fixed, with a working test to prevent it happening again, then to postpone it due to uncertainty on the test implementation. We can always create a new issue to fix the test later.

  • larowlan committed 3442528 on 8.5.x
    Issue #2744663 by jholding, rivimey, John Cook, hctom, mahalingam_cs:...

  • larowlan committed 8db10b6 on 8.4.x
    Issue #2744663 by jholding, rivimey, John Cook, hctom, mahalingam_cs:...
larowlan’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Fixed
+++ b/core/modules/system/tests/src/Functional/Batch/PageTest.php
@@ -50,7 +50,15 @@ public function testBatchProgressPageTitle() {
+    $this->assertText('Batch Test', 'The test is in the html output.');

assertText is deprecated however there are already uses of it in this function so to minimize scope creep, not going to ask for it to be removed.

Committed as 3442528 and pushed to 8.5.x

Cherry-picked as 8db10b6 and pushed to 8.4.x.

Thanks all

Status: Fixed » Closed (fixed)

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