OutboundPathProcessor is not appending $options array? I have a simple OutboundPathProcessor that should append a query string and a URL fragment, but nothing is happening.

mymodule.services.yml

services:
  mymodule.path_processor:
    class: Drupal\mymodule\PathProcessor\MyModulePathProcessor
    tags:
      - { name: path_processor_outbound }


MyModulePathProcessor.php

namespace Drupal\mymodule\PathProcessor;

use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Symfony\Component\HttpFoundation\Request;

class MyModulePathProcessor implements OutboundPathProcessorInterface {

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

    $options['query']['foo'] = 'bar';
    $options['fragment'] = 'baz';

    return $path;
  }

}


It seems the $options array is passed by reference, and in fact LanguageNegotiationUrl::processOutbound is placing multiple values in the $options array. 

Why doesn't my code work?

I just figured out that it does work if I add a URL prefix using $options['prefix'] = 'prefix/';, so some options are getting applied.
Why aren't fragment and query used?
It seems there is a bug report for that. I found a reference to that issue in a inline comment inside LanguageNegotiationContentEntity::processOutbound().

At the moment, after applying the patch from that issue, query parameters get added to the URL as you would expect and without any need to instantiate 'prefix', but fragment doesn't. More work/comments should go into that issue to assist with resolving it.

As an alternative and in order to get fragments to work, you could try extending the Drupal\Core\Routing\UrlGenerator and replace the url_generator.non_bubbling service. (See https://www.drupal.org/node/2026959.)