Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Twig function, csrfToken() to auto generate the input field #4961

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
New Twig function, csrfToken() to auto generate the input field
  • Loading branch information
robertdown committed Feb 25, 2022
commit 8043411050d598e2fc6a52b18365dca1b24794a1
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