|
| 1 | +.. include:: /Includes.rst.txt |
| 2 | +.. index:: Extension development; Software Design Principles |
| 3 | +.. _extension-loading-order: |
| 4 | + |
| 5 | +======================= |
| 6 | +Extension loading order |
| 7 | +======================= |
| 8 | + |
| 9 | +In TYPO3, the order in which extensions are loaded can impact system behavior. |
| 10 | +This is especially important when an extension overrides, extends, or modifies |
| 11 | +the functionality of another. TYPO3 initializes extensions in a defined order, |
| 12 | +and if dependencies are not loaded beforehand, it can lead to unintended |
| 13 | +behavior. |
| 14 | + |
| 15 | +.. _extension-loading-order-composer: |
| 16 | + |
| 17 | +Composer-based installations: Loading order via composer.json |
| 18 | +============================================================= |
| 19 | + |
| 20 | +In Composer-based installations, extensions and dependencies are |
| 21 | +installed based on the configuration in the |
| 22 | +:file:`composer.json <extension-composer-json>` file. |
| 23 | + |
| 24 | +For example, if an extension relies on or modifies functionality provided by |
| 25 | +the :php:`ext:felogin` system extension, the dependency should be defined |
| 26 | +as follows: |
| 27 | + |
| 28 | +.. literalinclude:: _snippets/_require-composer.json |
| 29 | + :language: json |
| 30 | + :caption: Excerpt of EXT:my_extension/composer.json |
| 31 | + |
| 32 | +This ensures that TYPO3 loads the extension **after** the |
| 33 | +:php:`ext:felogin` system extension. |
| 34 | + |
| 35 | +Instead of `require`, extensions can also use the `suggest` section. |
| 36 | +Suggested extensions, if installed, are loaded **before** the current one — |
| 37 | +just like required ones — but without being mandatory. |
| 38 | + |
| 39 | +A typical use case is suggesting an extension that provides optional widgets, |
| 40 | +such as for EXT:dashboard. |
| 41 | + |
| 42 | +.. _extension-loading-order-classic: |
| 43 | + |
| 44 | +Classic installations: Loading order via ext_emconf.php |
| 45 | +======================================================= |
| 46 | + |
| 47 | +In classic installations, extensions are loaded based on the order defined in the |
| 48 | +:file:`ext_emconf.php` file. |
| 49 | + |
| 50 | +For example, if an extension relies on or modifies functionality provided by |
| 51 | +the :php:`ext:felogin` system extension, the dependency should be defined |
| 52 | +as follows: |
| 53 | + |
| 54 | +.. literalinclude:: _snippets/_depends-ext-emconf.php |
| 55 | + :language: json |
| 56 | + :caption: EXT:my_extension/ext_emconf.php |
| 57 | + |
| 58 | +This ensures that TYPO3 loads the extension **after** the |
| 59 | +:php:`ext:felogin` system extension. |
| 60 | + |
| 61 | +As with Composer, you can use the `suggest` section instead of `depends`. |
| 62 | +Suggested extensions, if installed, are loaded **before** the current one, |
| 63 | +without being strictly required. |
| 64 | + |
| 65 | +.. _extension-loading-order-composer-and-classic: |
| 66 | + |
| 67 | +Keeping the loading order in sync between Composer-based and classic installations |
| 68 | +================================================================================== |
| 69 | + |
| 70 | +If your extension supports both Composer-based and classic TYPO3 installations, |
| 71 | +you should keep dependency information consistent between the |
| 72 | +:file:`composer.json <extension-composer-json>` and |
| 73 | +:ref:`ext_emconf.php <ext_emconf-php>` files. |
| 74 | + |
| 75 | +This is especially important for managing dependency constraints such as |
| 76 | +`depends`, `conflicts`, and `suggests`. Use the equivalent fields in |
| 77 | +:file:`composer.json <extension-composer-json>` — `require`, `conflict`, and |
| 78 | +`suggest` — to ensure consistent loading behavior across both installation types. |
0 commit comments