Skip to content

Commit 9ea8d32

Browse files
[Backport 13.4] [TASK] Overhaul extension development howto model extensions (#6249)
* [TASK] Overhaul extension development howto model extensions Releases: main, 13.4 * [TASK] Overhaul extension development howto model extensions Releases: main, 13.4 --------- Co-authored-by: Sarah McCarthy <[email protected]>
1 parent e449939 commit 9ea8d32

File tree

1 file changed

+74
-69
lines changed
  • Documentation/ExtensionArchitecture/HowTo/ExtendExtbaseModel

1 file changed

+74
-69
lines changed

Documentation/ExtensionArchitecture/HowTo/ExtendExtbaseModel/Index.rst

Lines changed: 74 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,48 @@
88
Extending an Extbase model
99
==========================
1010

11-
Once you have added an additional field to the
12-
:ref:`TCA <extending-tca>` the new field will be displayed in the backend forms.
11+
Once you have added a new field to the
12+
:ref:`TCA <extending-tca>` it will be displayed in the backend forms.
1313

1414
However, if the extension you are trying to extend is based on :ref:`Extbase <extbase>` the new
1515
field is not available in the frontend out of the box. Further steps are
1616
needed to make the fields available. These steps will not work in all cases.
1717

18+
.. _extending-extbase-model_quick_overview:
19+
1820
Quick overview
1921
==============
2022

2123
Follow these steps:
2224

2325
.. rst-class:: bignums
2426

25-
#. Is your extension the :ref:`only one trying to
27+
#. Is your extension the :ref:`only extension trying to
2628
extend <extending-extbase-model_find_other_extending_models>` the original
27-
model within your installation?
29+
model in your installation?
2830

2931
#. :ref:`Find the original model <extending-extbase-model_find_original_model>`.
30-
If this model has the modifier :php:`final` refer
31-
to the extension's documentation on how to display additional fields.
32+
If the model has the :php:`final` modifier, refer
33+
to the extension documentation on how to display additional fields.
3234

3335
#. :ref:`Find the original repository <extending-extbase-model_find_original_repository>`.
34-
Again, if the repository is :php:`final` refer
35-
to the extension's documentation on how to display additional fields.
36+
If the repository is :php:`final`, refer
37+
to the extension documentation on how to display additional fields.
3638

3739
#. :ref:`Extend the original model <extending-extbase-model_extend_original_model>`
38-
in your custom extension or :ref:`sitepackage <site-package>`.
40+
in your extension or :ref:`sitepackage <site-package>`.
3941

4042
#. :ref:`Register your extended model <extending-extbase-model_register_extended_model>`
41-
with the according database table in
43+
with the corresponding database table in
4244
:file:`EXT:my_extension/Configuration/Extbase/Persistence/Classes.php`.
4345

4446
#. :ref:`Extend the original repository <extending-extbase-model_register_extended_model>`
45-
in your custom extension or sitepackage.
47+
in your extension or sitepackage.
4648

4749
#. :ref:`Register your extended repository <extending-extbase-model_register_extended_repository>`
48-
to be used instead of the original one.
50+
so that it is used instead of the original one.
51+
52+
.. _extending-extbase-model_steps:
4953

5054
Step by step
5155
============
@@ -55,49 +59,49 @@ Step by step
5559
Are you the only one trying to extend that model?
5660
-------------------------------------------------
5761

58-
Within your installation you can search for other classes that are extending
62+
Search for other classes in your installation that extend
5963
the original model or repository (see below).
6064

6165
If the model is already extended but you only need to create the fields for
6266
your current installation you can proceed by extending the extended model.
63-
In the following steps of this tutorial use the previously extended model
64-
as original model.
67+
In the rest of this tutorial use the extended model
68+
as the original model.
6569

66-
If the model has different :ref:`Record types <extbase-persistance-record-types>`
67-
you can decide to introduce a new type and
68-
only extend that one type. This is, for example, commonly done when extending
69-
the model of :composer:`georgringer/news`.
70+
If the model has different :ref:`record types <extbase-persistance-record-types>`
71+
you can add a new type and
72+
only extend that one type. This is commonly done when extending
73+
the :composer:`georgringer/news` model.
7074

71-
If you are planning to publish your extension that extends another extensions
72-
model, research on `Packagist <https://packagist.org/>`__ and the
75+
If you are planning to publish this extension, search
76+
`Packagist <https://packagist.org/>`__ and the
7377
`TER (TYPO3 extension repository) <https://extensions.typo3.org/>`__ for
74-
extensions that are already extending the model. If necessary, put them in
75-
the `conflict` sections of you extensions :ref:`composer-json` and
78+
extensions that also extend the original model. If necessary, put them in
79+
the `conflict` sections of your extension's :ref:`composer-json` and
7680
:ref:`ext_emconf-php`.
7781

7882
.. _extending-extbase-model_find_original_model:
7983

80-
Find the original model
81-
-----------------------
84+
Finding the original model
85+
--------------------------
8286

83-
The model should be located in the original extension at path
84-
:file:`EXT:original_extension/Classes/Domain/Model/` or a subdirectory
85-
thereof. If the model is not found here it might
87+
The model should be located in the original extension in
88+
:file:`EXT:original_extension/Classes/Domain/Model/` or a subdirectory. If the
89+
model is not there it might:
8690

87-
* be situated in a different extension
88-
* not be an Extbase model (you cannot follow this tutorial then)
91+
* be located in a different extension
92+
* not be an Extbase model (then you cannot follow this tutorial)
8993

90-
You can also try to debug the model in a Fluid template that outputs the model:
94+
You can also try debugging the model with a Fluid template that outputs the model:
9195

9296
.. code-block:: html
9397
:caption: Some Fluid template that uses the model
9498

9599
<f:debug>{someModel}</f:debug>
96100

97-
If you debugged the correct object the fully qualified PHP name of the model
98-
will appear in the debug output. This gives you further hints on where to find
101+
If you debugged the correct object, the fully qualified PHP name of the model
102+
will appear in the debug output. This will give you further hints on where to find
99103
the associated class. You could, for example, do a full text search for the
100-
namespace of this class.
104+
namespace of the class.
101105

102106
If the class of the model is final:
103107

@@ -108,56 +112,55 @@ If the class of the model is final:
108112
// ...
109113
}
110114
111-
It cannot be extended by means of this tutorial. Refer to the documentation of
115+
it cannot be extended using the instructions in this tutorial. Refer to the documentation of
112116
the original extension.
113117

114118
.. _extending-extbase-model_find_original_repository:
115119

116-
Find the original repository
117-
----------------------------
120+
Finding the original repository
121+
-------------------------------
118122

119-
In Extbase the repository of a model mostly has to have the same class name as
120-
the model, prefixed with "Repository". It has to be located in the same domain
121-
directory as the model, but in the subfolder :file:`Repository`.
123+
In Extbase the repository of a model usually has the same class name as
124+
the model, prefixed with "Repository". It is located in the same domain
125+
directory as the model, but in the :file:`Repository` subfolder.
122126

123-
For example, if the model is found in :file:`Classes/Domain/Model/SomeModel.php`
127+
For example, if the model is :file:`Classes/Domain/Model/SomeModel.php`
124128
the repository is located in
125129
:file:`Classes/Domain/Repository/SomeModelRepository.php`.
126130

127-
* If you do not find this repository but found the model the extension might
128-
not use an Extbase repository. This tutorial does not help you in this
129-
case as it can only be applied to Extbase repositories.
130-
* If you find a repository in this name scheme but it does not extend
131-
directly or indirectly the class
132-
:php:`TYPO3\CMS\Extbase\Persistence\Repository` you are also not dealing
133-
with an Extbase repository.
131+
* If you can't find the repository but have found the model, the extension might
132+
not be using an Extbase repository. This tutorial will not help you in this
133+
case as it is only relevant for Extbase repositories.
134+
* If you find a repository according to this naming scheme but it does not extend
135+
the class
136+
:php:`TYPO3\CMS\Extbase\Persistence\Repository` directly or indirectly, it
137+
is also not an Extbase repository.
134138
* If the repository is final it cannot be extended.
135139

136-
In all these cases refer to the extension's documentation on how to extend it.
140+
In all these cases refer to the extension documentation on how to extend it.
137141

138142
.. _extending-extbase-model_extend_original_model:
139143

140144
Extend the original model
141145
-------------------------
142146

143-
We assume you already extended the database table and TCA (table configuration array)
144-
as described in :ref:`Extending TCA <extending-tca>`. Extend the
145-
original model by a custom class in your extension:
147+
We assume that you have already extended the database table and TCA (table
148+
configuration array) as described in :ref:`Extending TCA <extending-tca>`. Extend the
149+
original model in your extension using a class:
146150

147151
.. literalinclude:: _MyExtendedModel.php
148152
:language: php
149153
:caption: EXT:my_extension/Classes/Domain/Model/MyExtendedModel.php
150154

151-
Add all additional fields that you require. By convention the database
152-
fields are usually prefixed with your extension's name and so are the
153-
names in the model.
155+
Add all the additional fields that you require. By convention the database
156+
fields and the model names are prefixed with the name of your extension.
154157

155158
.. _extending-extbase-model_register_extended_model:
156159

157160
Register the extended model
158161
---------------------------
159162

160-
The extended model needs to be registered for :ref:`Extbase persistence <extbase-Persistence>` in file
163+
The extended model needs to be registered for :ref:`Extbase persistence <extbase-Persistence>` in files
161164
:file:`Configuration/Extbase/Persistence/Classes.php` and :file:`ext_localconf.php`.
162165

163166
.. literalinclude:: _Classes.php
@@ -173,44 +176,46 @@ The extended model needs to be registered for :ref:`Extbase persistence <extbase
173176
Extend the original repository (optional)
174177
-----------------------------------------
175178

176-
Likewise extend the original repository:
179+
Similarly, extend the original repository:
177180

178181
.. literalinclude:: _MyExtendedModelRepository.php
179182
:language: php
180183
:caption: EXT:my_extension/Classes/Domain/Repository/MyExtendedModelRepository.php
181184

182-
The rule that a repository must follow the name schema of the model also
185+
The rule that a repository must follow the naming schema of the model also
183186
applies when extending model and repository. So the new repository's name must
184-
end on "Repository" and it must be in the directory :file:`Domain/Repository`.
187+
end with "Repository" and it must be in the :file:`Domain/Repository` directory.
185188

186-
If you have no need for additional repository methods you can leave the body of
187-
this class empty. However, for Extbase internal reasons you have to create this
188-
repository even if you need no additional functionality.
189+
If you don't need additional repository methods you can leave the body of
190+
this class empty. However, for internal Extbase reasons you have to create the
191+
repository even if you don't add additional functionality.
189192

190193
.. _extending-extbase-model_register_extended_repository:
191194

192195
Register the extended repository
193196
--------------------------------
194197

195-
The extended repository needs to be registered with Extbase in your extensions
196-
:file:`EXT:my_extension/ext_localconf.php`. This step tells
198+
The extended repository needs to be registered with Extbase in your extension file
199+
:file:`EXT:my_extension/ext_localconf.php`. This tells
197200
Extbase to use your repository instead of the original one whenever the original
198201
repository is requested via Dependency Injection in a controller or service.
199202

200203
.. literalinclude:: _ext_localconf_repository.php
201204
:language: php
202205
:caption: EXT:my_extension/ext_localconf.php
203206

207+
.. _extending-extbase-model_alternative_strategies:
208+
204209
Alternative strategies to extend Extbase models
205210
===============================================
206211

207-
There is a dedicated TYPO3 extension to extend models and functions to classes by
212+
There is a TYPO3 extension that extends models and functions to classes by
208213
implementing the proxy pattern: `Extbase Domain Model Extender
209214
(evoweb/extender) <https://extensions.typo3.org/extension/extender>`__.
210215

211-
This extension can - for example - be used to
212-
:ref:`Extend models of tt_address <friendsoftypo3/tt-address:development-extend-ttaddress>`.
216+
This extension can be used to
217+
:ref:`extend models of tt_address <friendsoftypo3/tt-address:development-extend-ttaddress>`, for example.
213218

214-
The commonly used extension `EXT:news (georgringer/news)` supplies a special
215-
generator that can be used to :ref:`add custom fields to news models
219+
The popular extension `EXT:news (georgringer/news)` has a special
220+
generator that can be used to :ref:`add new fields to news models
216221
<georgringer/news:proxyClassGenerator>`.

0 commit comments

Comments
 (0)