feat(ext-tracking): Add tracking extension for HTML/JS snippets
Adds a new extension allowing injection of custom code into the page head. Includes an admin interface for saving snippets, secure save routes with CSRF protection, and tests verifying the functionality. Also updates core Extensions.php to support callable HTML blocks for lazy evaluation.
This commit is contained in:
@@ -68,10 +68,10 @@ class Extensions
|
||||
|
||||
/**
|
||||
* Register an HtmlBlock.
|
||||
* @param string $html
|
||||
* @param string|callable $html
|
||||
* @param string $location
|
||||
*/
|
||||
public static function registerHtmlBlock(string $html, string $location = 'head') {
|
||||
public static function registerHtmlBlock(string|callable $html, string $location = 'head') {
|
||||
self::$htmlBlocks[$location][] = $html;
|
||||
}
|
||||
|
||||
@@ -245,7 +245,11 @@ class Extensions
|
||||
*/
|
||||
public static function getHtmlBlocks(string $location = 'head'): string
|
||||
{
|
||||
return implode('', self::$htmlBlocks[$location]);
|
||||
$html = '';
|
||||
foreach (self::$htmlBlocks[$location] as $block) {
|
||||
$html .= is_string($block) ? $block : $block();
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user