Skip to content

Commit

Permalink
Trigger Craft response events
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Oct 16, 2024
1 parent 986d994 commit 7295d87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "putyourlightson/craft-spark",
"description": "A reactive hypermedia framework for Craft CMS.",
"version": "0.0.1",
"version": "0.0.3",
"type": "craft-plugin",
"license": "proprietary",
"require": {
"php": ">=8.2",
"craftcms/cms": "^5.4.0",
"putyourlightson/datastar-php": "0.0.1"
"putyourlightson/datastar-php": "0.0.3"
},
"require-dev": {
"craftcms/ecs": "dev-main",
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/ResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function actionIndex(): void
$params = $this->getParams();

Spark::$plugin->response->process($config, $params);

exit();
}

private function getParams()
Expand Down
8 changes: 7 additions & 1 deletion src/services/ResponseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ public function process(string $config, array $params): void
{
$config = $this->getValidatedConfig($config);
Craft::$app->getSites()->setCurrentSite($config->siteId);

$variables = array_merge($params, $config->variables);

$this->renderTemplate($config->template, $variables);

// Trigger Craft response events so that plugins can do their thing.
Craft::$app->getResponse()->trigger(Response::EVENT_AFTER_PREPARE);
Craft::$app->getResponse()->trigger(Response::EVENT_AFTER_SEND);

$this->response->end();
}

/**
Expand Down

0 comments on commit 7295d87

Please sign in to comment.