/
hooks.html
74 lines (60 loc) · 2.63 KB
/
hooks.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
layout: default
navPage: docs
heading: Hooks
breadcrumbs:
- Module Development,/module_development/
- Form Tools 3,/module_development/ft3/
- Hooks
prev: Hooks::registerHook(),/module_development/ft3/register_hook/
next: Methodology,/module_development/ft3/hooks_methodology/
categories: module_development
versions: FT3
---
{% include open_section.html nav='nav_module_development_ft3.html' selected='hooks' nav_width=4 %}
<p>
Any programmer can edit the Form Tools Core code to make whatever changes they need,
but the drawback is that any time they do this, they run the risk of having those changes
overwritten the next time the script is upgraded. This is a problem!
</p>
<p>
Enter Hooks. Hooks are a solution employed by many extensible web applications to solve
this situation (or at least patch it!). Hooks can be implemented in a wide variety of
ways, so the following pages outline our approach.
</p>
<p>
Hooks let programmers do two things: (1) have their code executed at certain locations
(<b>code hooks</b>) and (2) have their own HTML displayed in the main Form Tools webpages
(<b>template hooks</b>). When combined, this opens up a wide range of functionality
that was previously impossible to do safely. Let's take a closer look at each of these
hook types.
</p>
<h3>Code Hooks</h3>
<p>
Littered throughout the Form Tools code - mostly found in getter and setter functions -
there are numerous code hooks, where module developers can attach their own code. If you're
looking through the code, look for lines like this:
</p>
{% codemirror php %}
extract(Hooks::processHookCalls("main", compact("account_info"), array("account_info")), EXTR_OVERWRITE);
{% endcodemirror %}
<p>
Basically what this does it pass off execution control to the ft_process_hooks function,
which calls all custom module functions that have been assign to the hook ("main", uniquely
identified by the calling function). It specifies what variables are passed and what
may be overwritten.
</p>
<h3>Template Hooks</h3>
<p>
Template hooks are probably simpler to understand. In the Smarty templates, there are
a number of locations where module developers may have their own HTML inserted into the
page. This can let you do things like add fields to forms, insert information or text
for the benefit of the user, or anything else. Template hooks look like this:
</p>
{% codemirror smarty %}
{template_hook location="admin_edit_client_settings_top"}
{% endcodemirror %}
<p>
For a list of template hooks, <a href="{{site.baseurl}}/module_development/ft3/template_hooks/">click here</a>.
</p>
{% include close_section.html %}