Skip to content

Commit f8ff8a8

Browse files
feat(form): header hook
1 parent d9afaad commit f8ff8a8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

inc/form.class.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,4 +2489,33 @@ public static function getFormListQuery() {
24892489

24902490
return $condition;
24912491
}
2492+
2493+
/**
2494+
* Get the extra content from other plugins to be added to the form header
2495+
*
2496+
* @return string
2497+
*/
2498+
public function getExtraHeader(): string {
2499+
global $PLUGIN_HOOKS;
2500+
2501+
$extra_header = "";
2502+
2503+
$callbacks = $PLUGIN_HOOKS['formcreator_insert_header'] ?? [];
2504+
foreach ($callbacks as $plugin => $callback) {
2505+
// Make sure the supplied hook is a valid callback
2506+
if (!is_callable($callback)) {
2507+
trigger_error(
2508+
"Invalid 'formcreator_insert_header' hook for '$plugin' plugin",
2509+
E_USER_WARNING
2510+
);
2511+
}
2512+
2513+
// Insert extra plugin header if not empty
2514+
if ($extra_plugin_header = call_user_func($callback, $this)) {
2515+
$extra_header .= $extra_plugin_header;
2516+
}
2517+
}
2518+
2519+
return $extra_header;
2520+
}
24922521
}

inc/formanswer.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ public function showForm($ID, $options = []) {
530530
if (!empty($this->fields['content'])) {
531531
echo '<div class="form_header">';
532532
echo html_entity_decode($this->fields['content']);
533+
echo html_entity_decode($form->getExtraHeader());
533534
echo '</div>';
534535
}
535536

templates/pages/userform.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
{% if item.fields['content'] != '' %}
5454
<div class="form_header">
5555
{{ __(item.fields['content'], domain)|safe_html }}
56+
{{ item.getExtraHeader()|safe_html }}
5657
</div>
5758
{% endif %}
5859
<ol>

0 commit comments

Comments
 (0)