New answers tagged

1

You need to give the router a nudge towards what $politician is supposed to be for the automatic up-casting to kick in. There are two ways to do that: Type-hint the variable in the controller method: function build(Politician $politician) { See EntityResolverManager::setParametersFromReflection for details Explicitly set the parameter type in the route ...


1

I guess you need to do a route parameter upcasting: entity.politician.about_me: path: '/politician/{politician}/about-me' defaults: _controller: '\Drupal\pw_basic\Controller\PoliticianFrontend\AboutMe::build' _title_callback: '\Drupal\pw_basic\Controller\PoliticianFrontend\AboutMe::title' requirements: _entity_access: 'politician.view' ...


0

There is a syntax error here Drupal::currentUser()->id() should be \Drupal::currentUser()->id() and also explode("/", $_SERVER["REQUEST_URI"])[2] gives you only people not the user id, to use User::load.


0

Here is a concrete example of what code needs to be written so that when hitting a url such as : www.my-website.com/my-pretty-alias You actually display the content of the following page : www.my-website.com/my-technical-needed-path/such-as/node/8 but my-pretty-alias is displayed in the url bar In my_module.services.yml file : services: my_module....


0

It seems you could use the service_collector to just add your custom ContextualPathBasedBreadcrumbBuilder. For that just add in your modules services.yml: my_custom_module.breadcrumb: class: Drupal\ my_custom_module.breadcrumb\CustomBreadcrumbBuilder arguments: ['@router.request_context', '@access_manager', '@router', '@path_processor_manager', '@...


0

You forgot to give the route name. It should be module_name.route_name (example: resume.application) resume.application: path: '/resume/myform' defaults: _title: 'Application form' _form: '\Drupal\resume\Form\ResumeForm' requirements: _permission: 'access content' For more info on routing refer to this link


1

DynamicRoutesAlter.php Problem #1 - preg_replace() without pattern $url = preg_replace('_', '-', $key); The $url will be always NULL, because you are using preg_replace() without regexp, use instead str_replace() or write appropriate regexp pattern: '/_/'. Solution #1 $url = preg_replace('/_/', '-', $key); Solution #2 $url = str_replace('_', '-', $key)...


Top 50 recent answers are included