0

I've developed a module which generates and displays dynamic content. The title of the page is also generated dynamically in the controller as show below:

if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) { 
  $route->setDefault('_title', strval($title))
}

This provoques each title is marked as untranslated text and fills the locales_source table.

I tried to use this line to stop this

$route->setDefault('_disable_route_normalizer', TRUE)

but it doesn't work.

And I tried to use

['#title' => $title]

and it doesn't work.

How to avoid this?

1

Create a "title" function in your controller and declare it in your route, like here ( _title_callback):

entity.node_type.edit_form:
  path: '/admin/structure/types/manage/{node_type}'
  defaults:
    _entity_form: 'node_type.edit'
    _title_callback: '\Drupal\Core\Entity\Controller\EntityController::title'
  requirements:
    _permission: 'administer content types'
  • 1
    Or if you buld your routes dynamically like so: $route->setDefault('_title_callback', EntityController::class . '::addBundleTitle'); – Rainer Feike Aug 22 '18 at 11:09
  • Thank's . You put me on the way . The solution was this : $route->setDefault('_title_callback', function() use($title){ return $title;}) – Agriesean Aug 22 '18 at 14:18

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.

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