diff --git a/src/services/ResponseService.php b/src/services/ResponseService.php index 163012f..76dd580 100644 --- a/src/services/ResponseService.php +++ b/src/services/ResponseService.php @@ -37,14 +37,6 @@ public function init(): void $this->response = new DatastarResponse(); } - /** - * Returns whether the request is a Spark request. - */ - public function getIsRequest(): bool - { - return Craft::$app->getRequest()->getHeaders()->get('datastar-request') === 'true'; - } - /** * Processes the response. */ @@ -62,10 +54,6 @@ public function process(string $config, array $params): void */ public function runAction(string $route, array $params): ?array { - if (!$this->getIsRequest()) { - return null; - } - Craft::$app->getRequest()->getHeaders()->set('Accept', 'application/json'); $response = Craft::$app->runAction($route, $params); @@ -90,10 +78,6 @@ public function setStore(array $values): void private function sendEvent(string $type, string $content, array $options = []): void { - if (!$this->getIsRequest()) { - return; - } - $this->id++; $event = new DatastarEvent([ diff --git a/src/twigextensions/nodes/FragmentNode.php b/src/twigextensions/nodes/FragmentNode.php index 473e940..9c1f099 100644 --- a/src/twigextensions/nodes/FragmentNode.php +++ b/src/twigextensions/nodes/FragmentNode.php @@ -33,7 +33,6 @@ public function compile(Compiler $compiler): void $compiler ->raw(";\n") - ->write(Spark::class . "::\$plugin->response->sendFragment(\$content, \$options);\n") - ->write("echo \$content;\n"); + ->write(Spark::class . "::\$plugin->response->sendFragment(\$content, \$options);\n"); } } diff --git a/src/variables/SparkVariable.php b/src/variables/SparkVariable.php index 89f341b..9d0c82d 100644 --- a/src/variables/SparkVariable.php +++ b/src/variables/SparkVariable.php @@ -59,7 +59,7 @@ public function delete(string $template, array $variables = []): string */ public function getIsRequest(): bool { - return Spark::$plugin->response->getIsRequest(); + return Craft::$app->getRequest()->getHeaders()->get('datastar-request') === 'true'; } /**