0

I've got a customized OutboundPathProcesser that adds GET parameters to URLs starting from a specific node type targetting a specific node id. Basically whenever I'm on a node of type product, I add the node id as GET Parameter to all URLs leading to my enquiry node.

A simplified version of my code is below.

public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {

  $node = $request_stack->attributes->get('node');    
  if ($node->bundle() == 'product') {
    if ($path == $enquiryNodePath) {
      $options['query']['product_id'] = $node->id();
    }
  }
}

This mostly works, especially for enquiry links inside the full view of my products. But for enquiry links in menu blocks, the parameters are cached: When starting on a product page after cache clear, the GET parameters is appended on every page, when starting on a normal page, the GET parameters is never appended.

I greenly tried to add caching similar to LanguageNegotiationUrl:

public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {

  $node = $request_stack->attributes->get('node');    
  if ($node->bundle() == 'product') {
    if ($path == $enquiryNodePath) {
      if ($bubbleable_metadata) {
        $bubbleable_metadata
          ->addCacheContexts([
          'url.path',
        ]);
      }
      $options['query']['product_id'] = $node->id();
    }
  }
}

But this totally destroyed my site, it somehow corrupted the router table and even after disabling my module I was no longer able to rebuild the router table. I had to restore my site from a backup to fix the WSOD.

How do I correctly I make my OutboundPathProcessor / menu blocks cache-aware of the current node id?

(I do NOT want to disable caching for menu block with something like max-age=0)

  • What was the error message behind the WSOD? – 4k4 Jul 26 '18 at 9:12
  • Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: INSERT INTO {router} (name, fit, path, pattern_outline, number_parts, route) VALUES ... followed by a huge list of placeholders and values – Hudri Jul 26 '18 at 9:19
  • Note: This was on my development server with no other users on the site, so the deadlock was not caused by normal site usage. – Hudri Jul 26 '18 at 9:22
  • That doesn't sound like a problem adding that cache item would be likely to have caused...have you run through the same process again since restoring the database to confirm that one change was definitely to blame? – Clive Jul 26 '18 at 9:24
  • I'm not 100% certain, it was a bit of trial & error, but this was the most significant code change before I got the error. The 2nd significant change was applying the patch to make fragments work, but I still have this patch applied right now and it seems to work – Hudri Jul 26 '18 at 9:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.