@ERIKREAGAN • EngineSummit 2012
THE ANATOMY OF
AN EXTENSION
@ERIKREAGAN • EngineSummit 2012
WHO IS THIS GUY?
2
A family man
@ERIKREAGAN • EngineSummit 2012
WHO IS THIS GUY?
3
Jesus is my homeboy
@ERIKREAGAN • EngineSummit 2012
WHO IS THIS GUY?
4
World famous (I’m on the internet)
@ERIKREAGAN • EngineSummit 2012
WHO IS THIS GUY?
5
EE Reactor team member
@ERIKREAGAN • EngineSummit 2012
WHO IS THIS GUY?
6
Partner & Technical Director
@ERIKREAGAN • EngineSummit 2012
THE ANATOMY OF
AN EXTENSION
7
@ERIKREAGAN • EngineSummit 2012
GOALS
• Extensions in the context of Add-ons
• What are Hooks?
• How do Hooks relate to Ex...
@ERIKREAGAN • EngineSummit 2012
GOALS
• Caveats in using Extensions
• end_script explanation & use
• Returning data back t...
@ERIKREAGAN • EngineSummit 2012
ADD-ONS OVERVIEW
• Plugins
• Accessories
• Modules
• Fieldtypes
• Extensions
10
@ERIKREAGAN • EngineSummit 2012
PLUGINS
• Runtime add-ons
• No settings interface
• No installation required
• No unique d...
@ERIKREAGAN • EngineSummit 2012
PLUGINS
• No language file requirement
• Can format custom text fields
• Can provide Templat...
@ERIKREAGAN • EngineSummit 2012
ACCESSORIES
• Only shown in Control Panel
• EE handles installation & settings for you
• S...
@ERIKREAGAN • EngineSummit 2012
MODULES
• Can have a Control Panel interface
• Requires Language file
• Must be installed i...
@ERIKREAGAN • EngineSummit 2012
FIELDTYPES
• Fairly self-explanatory
• Fieldtypes for channel publish form
• Have correspo...
@ERIKREAGAN • EngineSummit 2012
EXTENSIONS
• Must be installed in the CP
• Can use EE's built-in simple settings builder
•...
@ERIKREAGAN • EngineSummit 2012
EXTENSIONS
• Manipulates data or processing during a given point
in a page load
• Must beh...
@ERIKREAGAN • EngineSummit 2012
WHAT ARE HOOKS?
18
@ERIKREAGAN • EngineSummit 201219
Hooks are used to alter or
augment the behavior of an
operating system, of applications,...
@ERIKREAGAN • EngineSummit 201220
How do hooks relate to Extensions?
@ERIKREAGAN • EngineSummit 201221
How do hooks relate to Extensions?
@ERIKREAGAN • EngineSummit 201222
HOOK PROCESSING
1. ExpressionEngine encounters a "hook" in the system
@ERIKREAGAN • EngineSummit 201223
HOOK PROCESSING
2.It checks the exp_extensions table to see if there is a
record with th...
@ERIKREAGAN • EngineSummit 201224
HOOK PROCESSING
3.If there is, then EE looks at the "class" column to
determine which ad...
@ERIKREAGAN • EngineSummit 201225
HOOK PROCESSING
4.If the add-on Extension file exists, it is loaded
@ERIKREAGAN • EngineSummit 201226
HOOK PROCESSING
5.Within that Extension class, the method listed is
executed.
@ERIKREAGAN • EngineSummit 201227
How do hooks relate to Extensions?
@ERIKREAGAN • EngineSummit 201228
HOOK PROCESSING
Low Seg2Cat Example Applied
1. ExpressionEngine encounters the sessions_...
@ERIKREAGAN • EngineSummit 201229
HOOK PROCESSING
Low Seg2Cat Example Applied
2.It checks the already-loaded extensions da...
@ERIKREAGAN • EngineSummit 201230
HOOK PROCESSING
Low Seg2Cat Example Applied
3.EE looks at the class "Low_seg2cat_ext" an...
@ERIKREAGAN • EngineSummit 201231
HOOK PROCESSING
Low Seg2Cat Example Applied
4.If third_party/low_seg2cat/ext.low_seg2cat...
@ERIKREAGAN • EngineSummit 201232
HOOK PROCESSING
Low Seg2Cat Example Applied
5.Finally EE executes the sessions_end metho...
@ERIKREAGAN • EngineSummit 2012
EXTENSION
PROCESSING
33
@ERIKREAGAN • EngineSummit 2012
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook...
@ERIKREAGAN • EngineSummit 2012
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook...
@ERIKREAGAN • EngineSummit 2012
HOOKS QUERY
SELECT
DISTINCT ee.*
FROM
exp_extensions ee
WHERE
enabled = 'y'
ORDER BY
hook,...
@ERIKREAGAN • EngineSummit 2012
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook...
@ERIKREAGAN • EngineSummit 2012
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook...
@ERIKREAGAN • EngineSummit 201239
Extensions playing well with others
@ERIKREAGAN • EngineSummit 2012
HOOK EXAMPLE
/* -------------------------------------------
/* 'delete_entries_start' hook...
@ERIKREAGAN • EngineSummit 2012
DEBUGGING METHODS
• Disable all extensions in the CP
• Disable all extensions in the config...
@ERIKREAGAN • EngineSummit 201242
Add-ons → Extensions
@ERIKREAGAN • EngineSummit 201243
config.php override
/*
|-------------------------------------------------------
| Express...
@ERIKREAGAN • EngineSummit 201244
config.php override
/*
|----------------------------------------------------------
| Expr...
@ERIKREAGAN • EngineSummit 201245
exp_extensions table
@ERIKREAGAN • EngineSummit 201246
All content available online at:
focuslabllc.com/blog
@ERIKREAGAN • EngineSummit 2012
@ERIKREAGAN
Partner, Focus Lab, LLC
@FocusLabLLC
47
Upcoming SlideShare
Loading in...5
×

The Anatomy of an Extension

135

Published on

One of the least understood aspects of ExpressionEngine is the class of add-ons known as Extensions. Many developers don’t understand why they exist, what they actually do or what problems they solve.

This confusion exists among both Extension users and developers alike. A quick browse of any ExpressionEngine support forum shows that a common first step to solving an issue is to “Disable all Extensions,” yet most don’t know why.

This was is designed to demystify the world of Extensions. The goal was to help everyone, from the general user to the new add-on developer, understand why Extensions exist, what they do and how they work.

You can also find the presentation in blog form here: http://focuslabllc.com/journal/the-anatomy-of-an-expressionengine-extension

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
135
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The Anatomy of an Extension

  1. 1. @ERIKREAGAN • EngineSummit 2012 THE ANATOMY OF AN EXTENSION
  2. 2. @ERIKREAGAN • EngineSummit 2012 WHO IS THIS GUY? 2 A family man
  3. 3. @ERIKREAGAN • EngineSummit 2012 WHO IS THIS GUY? 3 Jesus is my homeboy
  4. 4. @ERIKREAGAN • EngineSummit 2012 WHO IS THIS GUY? 4 World famous (I’m on the internet)
  5. 5. @ERIKREAGAN • EngineSummit 2012 WHO IS THIS GUY? 5 EE Reactor team member
  6. 6. @ERIKREAGAN • EngineSummit 2012 WHO IS THIS GUY? 6 Partner & Technical Director
  7. 7. @ERIKREAGAN • EngineSummit 2012 THE ANATOMY OF AN EXTENSION 7
  8. 8. @ERIKREAGAN • EngineSummit 2012 GOALS • Extensions in the context of Add-ons • What are Hooks? • How do Hooks relate to Extensions? • How are Extensions called by EE? 8
  9. 9. @ERIKREAGAN • EngineSummit 2012 GOALS • Caveats in using Extensions • end_script explanation & use • Returning data back to EE • Better Debugging Processes 9
  10. 10. @ERIKREAGAN • EngineSummit 2012 ADD-ONS OVERVIEW • Plugins • Accessories • Modules • Fieldtypes • Extensions 10
  11. 11. @ERIKREAGAN • EngineSummit 2012 PLUGINS • Runtime add-ons • No settings interface • No installation required • No unique db tables (typically) 11
  12. 12. @ERIKREAGAN • EngineSummit 2012 PLUGINS • No language file requirement • Can format custom text fields • Can provide Template tags • Small learning curve 12
  13. 13. @ERIKREAGAN • EngineSummit 2012 ACCESSORIES • Only shown in Control Panel • EE handles installation & settings for you • Small learning curve 13
  14. 14. @ERIKREAGAN • EngineSummit 2012 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
  15. 15. @ERIKREAGAN • EngineSummit 2012 FIELDTYPES • Fairly self-explanatory • Fieldtypes for channel publish form • Have corresponding Template tags 15
  16. 16. @ERIKREAGAN • EngineSummit 2012 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 often don’t) 16
  17. 17. @ERIKREAGAN • EngineSummit 2012 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
  18. 18. @ERIKREAGAN • EngineSummit 2012 WHAT ARE HOOKS? 18
  19. 19. @ERIKREAGAN • EngineSummit 201219 Hooks are used to alter or augment the behavior of an operating system, of applications, or of other software components. Wikipedia article on “Hooking”
  20. 20. @ERIKREAGAN • EngineSummit 201220 How do hooks relate to Extensions?
  21. 21. @ERIKREAGAN • EngineSummit 201221 How do hooks relate to Extensions?
  22. 22. @ERIKREAGAN • EngineSummit 201222 HOOK PROCESSING 1. ExpressionEngine encounters a "hook" in the system
  23. 23. @ERIKREAGAN • EngineSummit 201223 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)
  24. 24. @ERIKREAGAN • EngineSummit 201224 HOOK PROCESSING 3.If there is, then EE looks at the "class" column to determine which add-on to look in for this extension
  25. 25. @ERIKREAGAN • EngineSummit 201225 HOOK PROCESSING 4.If the add-on Extension file exists, it is loaded
  26. 26. @ERIKREAGAN • EngineSummit 201226 HOOK PROCESSING 5.Within that Extension class, the method listed is executed.
  27. 27. @ERIKREAGAN • EngineSummit 201227 How do hooks relate to Extensions?
  28. 28. @ERIKREAGAN • EngineSummit 201228 HOOK PROCESSING Low Seg2Cat Example Applied 1. ExpressionEngine encounters the sessions_end hook in the system
  29. 29. @ERIKREAGAN • EngineSummit 201229 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
  30. 30. @ERIKREAGAN • EngineSummit 201230 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
  31. 31. @ERIKREAGAN • EngineSummit 201231 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
  32. 32. @ERIKREAGAN • EngineSummit 201232 HOOK PROCESSING Low Seg2Cat Example Applied 5.Finally EE executes the sessions_end method within the ext.low_seg2cat.php file
  33. 33. @ERIKREAGAN • EngineSummit 2012 EXTENSION PROCESSING 33
  34. 34. @ERIKREAGAN • EngineSummit 2012 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
  35. 35. @ERIKREAGAN • EngineSummit 2012 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
  36. 36. @ERIKREAGAN • EngineSummit 2012 HOOKS QUERY SELECT DISTINCT ee.* FROM exp_extensions ee WHERE enabled = 'y' ORDER BY hook, priority ASC, class 36 From libraries/Extensions.php
  37. 37. @ERIKREAGAN • EngineSummit 2012 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
  38. 38. @ERIKREAGAN • EngineSummit 2012 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
  39. 39. @ERIKREAGAN • EngineSummit 201239 Extensions playing well with others
  40. 40. @ERIKREAGAN • EngineSummit 2012 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
  41. 41. @ERIKREAGAN • EngineSummit 2012 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
  42. 42. @ERIKREAGAN • EngineSummit 201242 Add-ons → Extensions
  43. 43. @ERIKREAGAN • EngineSummit 201243 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";
  44. 44. @ERIKREAGAN • EngineSummit 201244 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";
  45. 45. @ERIKREAGAN • EngineSummit 201245 exp_extensions table
  46. 46. @ERIKREAGAN • EngineSummit 201246 All content available online at: focuslabllc.com/blog
  47. 47. @ERIKREAGAN • EngineSummit 2012 @ERIKREAGAN Partner, Focus Lab, LLC @FocusLabLLC 47
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×