Rebuild routes when quick form config entities are saved/deleted.

This commit is contained in:
Michael Stenta 2023-10-09 11:19:29 -04:00
parent 96b6002f5d
commit 0067c85215
2 changed files with 28 additions and 0 deletions

View File

@ -175,4 +175,20 @@ class QuickFormInstance extends ConfigEntityBase implements QuickFormInstanceInt
}
}
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
\Drupal::service('router.builder')->setRebuildNeeded();
}
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
\Drupal::service('router.builder')->setRebuildNeeded();
}
}

View File

@ -146,6 +146,9 @@ class QuickFormTest extends FarmBrowserTestBase {
]);
$config_entity->save();
// Rebuild routes.
\Drupal::service('router.builder')->rebuildIfNeeded();
// Go to the quick form index and confirm that the requires_entity_test
// quick form item is visible.
$this->drupalGet('quick');
@ -157,6 +160,15 @@ class QuickFormTest extends FarmBrowserTestBase {
$this->drupalGet('quick/requires_entity_test');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($this->t('Test field'));
// Delete the config entity and confirm that it is removed.
$config_entity->delete();
\Drupal::service('router.builder')->rebuildIfNeeded();
$this->drupalGet('quick');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains($this->t('Test requiresEntity quick form'));
$this->drupalGet('quick/requires_entity_test');
$this->assertSession()->statusCodeEquals(404);
}
}