ERIKREAGAN • EngineSummit
THE ANATOMY OF
AN EXTENSION
Slide 2
Slide 2 text
ERIKREAGAN • EngineSummit
WHO IS THIS GUY?
2
A family man
Slide 3
Slide 3 text
ERIKREAGAN • EngineSummit
WHO IS THIS GUY?
3
Jesus is my homeboy
Slide 4
Slide 4 text
ERIKREAGAN • EngineSummit
WHO IS THIS GUY?
4
World famous (I’m on the internet)
Slide 5
Slide 5 text
ERIKREAGAN • EngineSummit
WHO IS THIS GUY?
5
EE Reactor team member
Slide 6
Slide 6 text
ERIKREAGAN • EngineSummit
WHO IS THIS GUY?
6
Partner & Technical Director
Slide 7
Slide 7 text
ERIKREAGAN • EngineSummit
THE ANATOMY OF
AN EXTENSION
7
Slide 8
Slide 8 text
ERIKREAGAN • EngineSummit
GOALS
• Extensions in the context of Add-ons
• What are Hooks?
• How do Hooks relate to Extensions?
• How are Extensions called by EE?
8
Slide 9
Slide 9 text
ERIKREAGAN • EngineSummit
GOALS
• Caveats in using Extensions
• end_script explanation & use
• Returning data back to EE
• Better Debugging Processes
9
ERIKREAGAN • EngineSummit
PLUGINS
• Runtime add-ons
• No settings interface
• No installation required
• No unique db tables (typically)
11
Slide 12
Slide 12 text
ERIKREAGAN • EngineSummit
PLUGINS
• No language file requirement
• Can format custom text fields
• Can provide Template tags
• Small learning curve
12
Slide 13
Slide 13 text
ERIKREAGAN • EngineSummit
ACCESSORIES
• Only shown in Control Panel
• EE handles installation & settings for you
• Small learning curve
13
Slide 14
Slide 14 text
ERIKREAGAN • EngineSummit
MODULES
• Can have a Control Panel interface
• Requires Language file
• Must be installed in the Control Panel
• Can utilize "actions"
• Can provide Template tags
14
Slide 15
Slide 15 text
ERIKREAGAN • EngineSummit
FIELDTYPES
• Fairly self-explanatory
• Fieldtypes for channel publish form
• Have corresponding Template tags
15
Slide 16
Slide 16 text
ERIKREAGAN • EngineSummit
EXTENSIONS
• Must be installed in the CP
• Can use EE's built-in simple settings builder
• Requires language file when you have settings
• Can have unique database tables (but they o en
don’t)
16
Slide 17
Slide 17 text
ERIKREAGAN • EngineSummit
EXTENSIONS
• Manipulates data or processing during a given point
in a page load
• Must behave nicely with other extensions
• Probably the steepest learning curve in add-ons
• Can only be used with existing system "hooks"
17
Slide 18
Slide 18 text
ERIKREAGAN • EngineSummit
WHAT ARE HOOKS?
18
Slide 19
Slide 19 text
ERIKREAGAN • EngineSummit
19
Hooks are used to alter or
augment the behavior of an
operating system, of applications,
or of other so ware components.
Wikipedia article on “Hooking”
Slide 20
Slide 20 text
ERIKREAGAN • EngineSummit
20
How do hooks relate to Extensions?
Slide 21
Slide 21 text
ERIKREAGAN • EngineSummit
21
How do hooks relate to Extensions?
Slide 22
Slide 22 text
ERIKREAGAN • EngineSummit
22
HOOK PROCESSING
1. ExpressionEngine encounters a "hook" in the system
Slide 23
Slide 23 text
ERIKREAGAN • EngineSummit
23
HOOK PROCESSING
2.It checks the exp_extensions table to see if there is a
record with the "hook" where the "enabled" column is
set to "y" (yes)
Slide 24
Slide 24 text
ERIKREAGAN • EngineSummit
24
HOOK PROCESSING
3.If there is, then EE looks at the "class" column to
determine which add-on to look in for this extension
Slide 25
Slide 25 text
ERIKREAGAN • EngineSummit
25
HOOK PROCESSING
4.If the add-on Extension file exists, it is loaded
Slide 26
Slide 26 text
ERIKREAGAN • EngineSummit
26
HOOK PROCESSING
5.Within that Extension class, the method listed is
executed.
Slide 27
Slide 27 text
ERIKREAGAN • EngineSummit
27
How do hooks relate to Extensions?
Slide 28
Slide 28 text
ERIKREAGAN • EngineSummit
28
HOOK PROCESSING
Low Seg2Cat Example Applied
1. ExpressionEngine encounters the sessions_end hook
in the system
Slide 29
Slide 29 text
ERIKREAGAN • EngineSummit
29
HOOK PROCESSING
Low Seg2Cat Example Applied
2.It checks the already-loaded extensions dataset for
an extension using the sessions_end hook which is
enabled
Slide 30
Slide 30 text
ERIKREAGAN • EngineSummit
30
HOOK PROCESSING
Low Seg2Cat Example Applied
3.EE looks at the class "Low_seg2cat_ext" and knows to
look for a folder called third_party/low_seg2cat
Slide 31
Slide 31 text
ERIKREAGAN • EngineSummit
31
HOOK PROCESSING
Low Seg2Cat Example Applied
4.If third_party/low_seg2cat/ext.low_seg2cat.php
exists, the file is loaded and an object is created
Slide 32
Slide 32 text
ERIKREAGAN • EngineSummit
32
HOOK PROCESSING
Low Seg2Cat Example Applied
5.Finally EE executes the sessions_end method within
the ext.low_seg2cat.php file
Slide 33
Slide 33 text
ERIKREAGAN • EngineSummit
EXTENSION
PROCESSING
33
Slide 34
Slide 34 text
ERIKREAGAN • EngineSummit
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook.
/* - Perform actions prior to entry deletion / take over deletion
*/
$edata = $this->extensions->call('delete_entries_start');
if ($this->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/
34
The “delete_entries_start” hook
Slide 35
Slide 35 text
ERIKREAGAN • EngineSummit
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook.
/* - Perform actions prior to entry deletion / take over deletion
*/
$edata = $this->extensions->call('delete_entries_start');
if ($this->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/
35
The “delete_entries_start” hook
Slide 36
Slide 36 text
ERIKREAGAN • EngineSummit
HOOKS QUERY
SELECT
DISTINCT ee.*
FROM
exp_extensions ee
WHERE
enabled = 'y'
ORDER BY
hook, priority ASC, class
36
From libraries/Extensions.php
Slide 37
Slide 37 text
ERIKREAGAN • EngineSummit
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook.
/* - Perform actions prior to entry deletion / take over deletion
*/
$edata = $this->extensions->call('delete_entries_start');
if ($this->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/
37
The “delete_entries_start” hook
Slide 38
Slide 38 text
ERIKREAGAN • EngineSummit
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook.
/* - Perform actions prior to entry deletion / take over deletion
*/
$edata = $this->extensions->call('delete_entries_start');
if ($this->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/
38
The “delete_entries_start” hook
Slide 39
Slide 39 text
ERIKREAGAN • EngineSummit
39
Extensions playing well with others
Slide 40
Slide 40 text
ERIKREAGAN • EngineSummit
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook.
/* - Perform actions prior to entry deletion / take over deletion
*/
$edata = $this->extensions->call('delete_entries_start');
if ($this->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/
40
The “delete_entries_start” hook
Slide 41
Slide 41 text
ERIKREAGAN • EngineSummit
DEBUGGING METHODS
• Disable all extensions in the CP
• Disable all extensions in the config.php file
• Disable one extension at a time in the database
41
Slide 42
Slide 42 text
ERIKREAGAN • EngineSummit
42
Add-ons → Extensions
Slide 43
Slide 43 text
ERIKREAGAN • EngineSummit
43
config.php override
/*
|-------------------------------------------------------
| ExpressionEngine Config Items
|-------------------------------------------------------
|
| The following items are for use with ExpressionEngine.
| The rest of the config items are for use with
| CodeIgniter.
|
*/
$config['app_version'] = "250";
$config['is_system_on'] = "y";
$config['allow_extensions'] = "y";
Slide 44
Slide 44 text
ERIKREAGAN • EngineSummit
44
config.php override
/*
|----------------------------------------------------------
| ExpressionEngine Config Items
|----------------------------------------------------------
|
| The following items are for use with ExpressionEngine.
| The rest of the config items are for use with
| CodeIgniter.
|
*/
$config['app_version'] = "250";
$config['is_system_on'] = "y";
$config['allow_extensions'] = "n";
Slide 45
Slide 45 text
ERIKREAGAN • EngineSummit
45
exp_extensions table
Slide 46
Slide 46 text
ERIKREAGAN • EngineSummit
46
All content available online at:
focuslabllc.com/blog