Skip to content

Commit

Permalink
New Twig function, csrfToken() to auto generate the input field (#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdown authored Feb 25, 2022
1 parent bda7c76 commit 4c623f5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace OpenEMR\Common\Twig;

use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Core\Header;
use OpenEMR\Core\Kernel;
use OpenEMR\Services\Globals\GlobalsService;
Expand Down Expand Up @@ -113,7 +114,13 @@ function ($eventName, $eventData = array()) {
$this->kernel->getEventDispatcher()->dispatch(new GenericEvent($eventName, $eventData), $eventName);
return ob_get_clean();
}
)
),
new TwigFunction(
'csrfToken',
function ($subject = 'default') {
return sprintf('<input type="hidden" name="_token" value="%s">', CsrfUtils::collectCsrfToken($subject));
}
),
];
}

Expand Down

0 comments on commit 4c623f5

Please sign in to comment.