File tree Expand file tree Collapse file tree
view/base/templates/script Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55use Magento \Framework \App \Response \HttpInterface as HttpResponseInterface ;
66use Magento \Framework \Controller \Result \Raw ;
7+ use Magento \Framework \Data \Form \FormKey ;
78
89class HtmlResult extends Raw
910{
11+ public function __construct (
12+ private readonly FormKey $ formKey
13+ ) {
14+ }
15+
1016 protected function render (HttpResponseInterface $ response )
1117 {
18+ $ response ->setHeader ('X-Magento-Form-Key ' , $ this ->formKey ->getFormKey ());
1219 $ response ->setHeader ('Content-Type ' , 'text/html ' );
1320
1421 return parent ::render ($ response );
Original file line number Diff line number Diff line change @@ -93,14 +93,20 @@ if ($interval < 10) {
9393 return;
9494 }
9595
96+ const formKey = Alpine.store('LokiComponents').formKey;
9697 await fetch('<?= $ escaper ->escapeUrl ($ componentUtil ->getPostUrl (
97- )) ?> ?form_key=' + LokiComponentFormKey + '&isAjax=true', {
98+ )) ?> ?form_key=' + formKey + '&isAjax=true', {
9899 method: 'POST',
99100 mode: 'same-origin',
100101 headers: this.getPostHeaders(),
101102 body: JSON.stringify(this.buildBody(requests))
102103 })
103104 .then(async response => {
105+ const formKey = response.headers.get('x-magento-form-key');
106+ if (formKey) {
107+ Alpine.store('LokiComponents').formKey = formKey;
108+ }
109+
104110 const body = await response.text();
105111 if (response.ok) {
106112 return body;
Original file line number Diff line number Diff line change 11<?php
22declare (strict_types=1 );
33
4- /** @version 2.4.1 */
5-
4+ use Loki \Components \Factory \ViewModelFactory ;
5+ use Loki \Components \Util \ComponentUtil ;
6+ use Magento \Framework \Escaper ;
67use Magento \Framework \View \Element \Template ;
78
9+ /** @version 2.4.1 */
810/** @var Template $block */
11+ /** @var Escaper $escaper */
12+ /** @var ViewModelFactory $viewModelFactory */
13+ /** @var ComponentUtil $componentUtil */
14+
15+ $ componentUtil = $ viewModelFactory ->create (ComponentUtil::class);
916?>
1017<script>
1118 document.addEventListener('alpine:init', () => {
1219 Alpine.store('LokiComponents', {
20+ formKey: '<?= $ escaper ->escapeJs ($ componentUtil ->getFormKey ()) ?> ',
1321 components: {},
1422 getComponentIds() {
1523 return Object.keys(this.components);
You can’t perform that action at this time.
0 commit comments