Хочу создать динамический routing в своём модуле. Добавляю в my_module.routing.yml:
- '\Drupal\my_module\Routing\MyModuleRoutes::routes'
в папке src создал папку Routing в ней класс роута: MyModuleRoutes.php с кодом:
<?php
namespace Drupal\my_module\Routing;
use
Symfony\Component\Routing\Route;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines dynamic routes.
*/
class MyModuleRoutes implements ContainerInjectionInterface {
/**
* @var EntityTypeManagerInterface $entityTypeManager.
*/
protected $entityTypeManager;
/**
* Constructs a new MyModuleRoutes.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function
create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function routes() {
$routes = [];
return $routes;
}
}
?>
Чищу кеш, включаю отладку, ставлю брекпоинт в методе routes() - ничего. Хотя отладчик нормально работает в других местах останавливается. Что не так делаю?
Комментарии
Этот код срабатывает только во время сброса кэша роутинга. Поэтому надо ставить брейкпоинт, а потом нажимать сброс кэша в браузере. Ни в коем случае не через консоль.
Даже не знаю, как сказать спасибо, чтобы правильно описать мои эмоции )))
Спасибо, друг! Я пол дня информацию ищу!
Что кеш знаю, но чистил через драш...