I'm having to write a new LanguageNegotiation plugin for an API because the language is not the first part of the URL (it's the third). But D8 refuses to recognise the route to the plugin for the config menu item.

I have been following the Language module itself as a model and there is no other mention of an equivalent route name for any of the other LanguageNegotiation plugins. I have tried replacing 'doublespeak' with 'language' in the route name (no change).

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "doublespeak.negotiation_api_url" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() 

So the doublespeak.routing.yml looks like this:

  path: '/admin/config/regional/language/detection/apiurl'
    _form: 'Drupal\doublespeak\Form\NegotiationApiUrlForm'
    _title: 'API URL language detection configuration'
    _permission: 'administer languages'

And the start of the plugin is this:

namespace Drupal\doublespeak\Plugin\LanguageNegotiation;

use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Url;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\language\LanguageSwitcherInterface;
use Symfony\Component\HttpFoundation\Request;

 * Class for identifying language in an API URL via an infix value.
 * @LanguageNegotiation(
 *   id = \Drupal\doublespeak\Plugin\LanguageNegotiation\LanguageNegotiationApiUrl::METHOD_ID,
 *   types = {\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE,
 *   \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT,
 *   \Drupal\Core\Language\LanguageInterface::TYPE_URL},
 *   weight = -10,
 *   name = @Translation("API URL"),
 *   description = @Translation("Language from an API URL (/api/<channel>/<market-language>/refdata/<>)."),
 *   config_route_name = "doublespeak.negotiation_api_url"
 * )
class LanguageNegotiationApiUrl extends LanguageNegotiationMethodBase implements InboundPathProcessorInterface, OutboundPathProcessorInterface, LanguageSwitcherInterface {

I've tried all sorts of options but can't make it work, and yes, I've cleared caches :-)

  • Make sure that your route is in the router table. That's all I can say, if all the files are in the right place, then this should work fine. – Berdir Jan 6 '16 at 18:35
  • This is why it's driving me nuts :-/ but yes, I'll check it's in the router table. Thanks. – Adaddinsane Jan 6 '16 at 22:35

Okay, the problem was not in either of these two files.

As suggested by @Berdir I checked the router table and found that my route was not there. However there is nothing wrong with the file.

So the problem must be somewhere else. What if a bad class/method reference could cause this?

As an experiment I replaced the '_form' property with one that was known to work and cleared the caches. Suddenly the route was there in the table.

Checking my Drupal\doublespeak\Form\NegotiationApiUrlForm file I discovered that in my copy/paste haste I hadn't changed the namespace so the form class effectively did not exist. And the route was not loaded into the table.

Fixed. (Phew.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.