Skip to content

Commit

Permalink
feat(form): header hook
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored Mar 9, 2022
1 parent d9afaad commit f8ff8a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2489,4 +2489,33 @@ public static function getFormListQuery() {

return $condition;
}

/**
* Get the extra content from other plugins to be added to the form header
*
* @return string
*/
public function getExtraHeader(): string {
global $PLUGIN_HOOKS;

$extra_header = "";

$callbacks = $PLUGIN_HOOKS['formcreator_insert_header'] ?? [];
foreach ($callbacks as $plugin => $callback) {
// Make sure the supplied hook is a valid callback
if (!is_callable($callback)) {
trigger_error(
"Invalid 'formcreator_insert_header' hook for '$plugin' plugin",
E_USER_WARNING
);
}

// Insert extra plugin header if not empty
if ($extra_plugin_header = call_user_func($callback, $this)) {
$extra_header .= $extra_plugin_header;
}
}

return $extra_header;
}
}
1 change: 1 addition & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public function showForm($ID, $options = []) {
if (!empty($this->fields['content'])) {
echo '<div class="form_header">';
echo html_entity_decode($this->fields['content']);
echo html_entity_decode($form->getExtraHeader());
echo '</div>';
}

Expand Down
1 change: 1 addition & 0 deletions templates/pages/userform.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
{% if item.fields['content'] != '' %}
<div class="form_header">
{{ __(item.fields['content'], domain)|safe_html }}
{{ item.getExtraHeader()|safe_html }}
</div>
{% endif %}
<ol>
Expand Down

0 comments on commit f8ff8a8

Please sign in to comment.