Lesson 7.4: Loading order and dependencies
When two extensions set the same setting or provide the same template, one of them wins, and the order of the
active extensions decides which. In this lesson learners see the order at work, declare what their extension
builds on in extension.xml, and read on the Extensions page where each extension really loads.
At a glance
| Course | Developers |
| Module | Module 7: Extensions |
| Duration | 40 minutes (15 presenting, 25 exercise) |
| Level | Advanced |
| Audience | Developers |
| Prerequisites | Lesson 7.3 |
Learning objectives
After this lesson, learners can:
- explain that an extension loaded earlier wins for settings and design templates;
- find which extension a setting comes from with
exp:ini where; - declare
<extends>,<requires>and<uses>inextension.xml; - explain what
[ExtensionSettings] ExtensionOrdering=enabledchanges; - read the real loading position on Setup > Extensions.
Trainer's notes
How to present it
Sources: Declaring dependencies in extension.xml, Extension loading order and The Extensions page.
Who wins (4 minutes). The order of
ActiveExtensions[]decides: an extension loaded earlier wins for settings and design templates.exp:ini wherelists every file that sets a variable, in load order, and the value in effect.Dependencies (5 minutes). In
extension.xml, after<metadata>:Element Loads your extension Use it for <extends>before the named one (yours wins) Overriding templates or settings of a base extension <requires>after the named one Something yours cannot work without <uses>after the named one Something yours uses when present The kernel reads them in
ezpExtension::getLoadingOrder()whenExtensionOrdering=enabled. They order only active extensions:<requires>does not activate the other one.The page (3 minutes). On Setup > Extensions each card shows where the extension really loads (Loads as number n) when dependencies move it; moves are reviewed before they are written.
Composer too (2 minutes). The same dependencies belong in
composer.json(requireorsuggest), so Composer installs what is needed.
Common questions
Why did my theme's template not win over another theme's? The other extension loads earlier, or declares that
it extends yours. Read the order and the <extends> blocks.
Does a broken extension.xml stop the site? It is reported in the debug output and its loading order is
ignored; check it with xmllint.
Should every extension declare dependencies? Every extension that overrides or needs another one, yes; it makes the order explainable instead of accidental.
Pitfalls
- Editing the order by hand on a live site. Use the Extensions page or
exp:iniwith a review; a wrong order can change templates across the site. <requires>as an installer. It orders; it installs and activates nothing.- Different order on development and live. Settings come from different files on each machine; compare with
exp:ini get site.ini/ExtensionSettings/ActiveExtensionson both.
Hands-on exercise
On the development installation.
Show the order of the active extensions:
php bin/php/console exp:ini get site.ini/ExtensionSettings/ActiveExtensions.Check whether dependency ordering is on:
php bin/php/console exp:ini where site.ini/ExtensionSettings/ExtensionOrdering.Find a setting several extensions set, for example
php bin/php/console exp:ini where design.ini/ExtensionSettings/DesignExtensions <sa>, and read which file comes first.Read a real dependency block:
grep -A8 "<dependencies>" extension/*/extension.xml | head -40.Add a dependency to your
extension.xml, after</metadata>:<dependencies> <uses> <extension name="ezjscore" /> </uses> </dependencies>Check it:
xmllint --noout extension/mysite_hello/extension.xml.Clear the INI cache (
php bin/php/ezcache.php --clear-tag=ini) and open Setup > Extensions. Find wheremysite_helloloads.Commit
extension.xmlwithUpdated: Declare the use of ezjscore.
Expected result
- Step 1: the list in load order with
mysite_helloin it. - Step 3: several files in load order, the value in effect at the end.
- Step 6: no output.
- Step 7: the card of
mysite_hello; withExtensionOrdering=enabledit loads afterezjscore. - The trainer asks each learner which element they would use for a theme that changes another theme's templates.
Quiz
- Two extensions provide the same template. Which one wins?
- Your theme overrides templates of a base theme. Which element do you declare?
A.
<requires>B.<uses>C.<extends>D.<metadata> - Which setting makes the kernel order extensions by their declared dependencies?
- Does
<requires>activate the other extension? - Which command lists every file that sets a variable, in load order?
Answers
- The one loaded earlier in the order of active extensions.
- C.
<extends>loads yours before the base, so yours wins. site.ini [ExtensionSettings] ExtensionOrdering=enabled.- No; it only orders active extensions.
exp:ini where <file>/<block>/<variable>.
Further reading
Related pages
- Module 7: Extensions
- Developers: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.