Hello,
I'm trying to add an extra path to the static build following the same pattern that its followed in Lunr module. However, that path is not being added to the /html folder.

The path I'm talking about is like "/modules/custom/mymodule/images/my_image.png". So I'm adding it to the event subscriber, expecting to have it exported to the /html folder.

However, it is not being exported. After some debugging, I found that StaticGenerator::requestPath() is not working correctly in this case. This line $response = $this->httpKernel->handle($request, HttpKernelInterface::MASTER_REQUEST); is returning a 404 error, even if the file is there actually. I believe this is because that path in the original site is not being served by PHP, but directly by the Apache server.

Reading the requestPath docs, it says this "This method should only be called for paths that need a Drupal bootstrap.". So it seems that the Lunr or my example use cases are not covered. However, it seems that it the Lunr module integration is working.

The annoying thing, is that I tried to replicate the Lunr module behavior and I found that Lunr index related json files are not being exported to /html folder anymore. Those files were exported in other tests I made before, so maybe I'm doing something wrong now.

Any idea?

Here are some environment details that could help:
Drupal version: 8.6.13
PHP version: 7.2.15
Tome version: 1.0-beta-4
Lunr version: 1.x-dev

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc created an issue. See original summary.

plopesc’s picture

Issue summary: View changes
plopesc’s picture

Title: Unable to add static files through 'collectPaths' event » Unable to add static files through 'collectPaths' event from the UI

Hello,

After a bit more of debugging, I found this is happening only when generating the static site from the UI. Generating the site from Drush, it works as expected. Both the Lunr json files and my custom image are being exported to the html file successfully.

From my basic understanding, it is happening because StaticGenerator::exportPaths() is the first thing executed by the drush command. However, generating the static site from the UI, it is executed at the end of the process, once these paths have been discarded because they return the 404 code in StaticCommand::RequestPath.

Regards.

plopesc’s picture

Status: Active » Needs review
FileSize
659 bytes

Here is a simple patch that worked for me. It just runs StaticGenerator::exportPaths() at the beginning of the process, as it's happening from Drush. Both lunr and my custom files are being imported and the rest of the static site is still working as expected, I think.

Regards.

  • plopesc authored 4a8c95f on 8.x-1.x
    Issue #3046290 by plopesc: Unable to add static files through '...
samuel.mortenson’s picture

Status: Needs review » Fixed

@plopesc This makes sense to me - thanks for figuring it out!

Status: Fixed » Closed (fixed)

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