DevelGenerateRoutes.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\devel_generate\Routing;
  3. use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
  4. use Drupal\Component\Plugin\PluginManagerInterface;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\Routing\Route;
  7. /**
  8. * Provides dynamic routes for devel_generate.
  9. */
  10. class DevelGenerateRoutes implements ContainerInjectionInterface {
  11. /**
  12. * Constructs a new devel_generate route subscriber.
  13. *
  14. * @param \Drupal\Component\Plugin\PluginManagerInterface $devel_generate_manager
  15. * The DevelGeneratePluginManager.
  16. */
  17. public function __construct(PluginManagerInterface $devel_generate_manager) {
  18. $this->DevelGenerateManager = $devel_generate_manager;
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function create(ContainerInterface $container) {
  24. return new static(
  25. $container->get('plugin.manager.develgenerate')
  26. );
  27. }
  28. public function routes() {
  29. $devel_generate_plugins = $this->DevelGenerateManager->getDefinitions();
  30. $routes = array();
  31. foreach ($devel_generate_plugins as $id => $plugin) {
  32. $label = $plugin['label'];
  33. $type_url_str = str_replace('_', '-', $plugin['url']);
  34. $routes["devel_generate.$id"] = new Route(
  35. "admin/config/development/generate/$type_url_str",
  36. array(
  37. '_form' => '\Drupal\devel_generate\Form\DevelGenerateForm',
  38. '_title' => "Generate $label",
  39. '_plugin_id' => $id,
  40. ),
  41. array(
  42. '_permission' => $plugin['permission'],
  43. )
  44. );
  45. }
  46. return $routes;
  47. }
  48. }