Rebuild routes when config-based CSV importers are saved/deleted.
This commit is contained in:
parent
e5c3bda5bf
commit
febdf94083
|
@ -9,3 +9,8 @@ services:
|
|||
arguments: [ '@database', '@current_user', '@tempstore.private' ]
|
||||
tags:
|
||||
- { name: 'event_subscriber' }
|
||||
farm_import_csv.config_subscriber:
|
||||
class: Drupal\farm_import_csv\EventSubscriber\CsvMigrationConfigSubscriber
|
||||
arguments: [ '@router.builder' ]
|
||||
tags:
|
||||
- { name: 'event_subscriber' }
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_import_csv\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Config\ConfigCrudEvent;
|
||||
use Drupal\Core\Config\ConfigEvents;
|
||||
use Drupal\Core\Routing\RouteBuilderInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Trigger a route rebuild when CSV importer configuration changes.
|
||||
*/
|
||||
class CsvMigrationConfigSubscriber implements EventSubscriberInterface {
|
||||
|
||||
/**
|
||||
* The router builder.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RouteBuilderInterface
|
||||
*/
|
||||
protected $routerBuilder;
|
||||
|
||||
/**
|
||||
* Constructs the CsvMigrationConfigSubscriber.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
|
||||
* The router builder service.
|
||||
*/
|
||||
public function __construct(RouteBuilderInterface $router_builder) {
|
||||
$this->routerBuilder = $router_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = ['rebuildRouter'];
|
||||
$events[ConfigEvents::DELETE][] = ['rebuildRouter'];
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the router builder a rebuild is needed when necessary.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigCrudEvent $event
|
||||
* The Event to process.
|
||||
*/
|
||||
public function rebuildRouter(ConfigCrudEvent $event) {
|
||||
$config = $event->getConfig();
|
||||
if (str_starts_with($config->getName(), 'migrate_plus.migration.')) {
|
||||
$this->routerBuilder->setRebuildNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue