Shared components
It is not always necessary or desired to automatically register all
related components based on the registration of a Data.
In some cases, for example, it may be necessary to use a component
more than once, e.g. if several modules use the same template and
thus one Presenter can be used for all those modules.
To be able to cover this special case, it is possible to specify
a concrete Data or Presenter for individual Data
in the Services. file.
Warning
Use of the Abstract required
The following examples are only applicable to Data that
extend the Abstract, since it provides the necessary
methods. These are not part of the Data interface.
Example 1: Shared Presenter
Assume that there are two modules Highlight Box and Highlight Text,
which are both rendered using the same Handlebars template. The data
provision is still done via two separate Data.
In the Services. file, we register both Data, but
specify a concrete method call set. This is normally
called automatically if it is not set manually.
# Configuration/Services.yaml
services:
Vendor\Extension\DataProcessing\HighlightBoxProcessor:
tags: ['handlebars.processor']
calls:
- setPresenter: ['@Vendor\Extension\Presenter\HighlightPresenter']
Vendor\Extension\DataProcessing\HighlightTextProcessor:
tags: ['handlebars.processor']
calls:
- setPresenter: ['@Vendor\Extension\Presenter\HighlightPresenter']
Both Data are now injected with the same Presenter, while all
other components continue to act independently.
Example 2: Shared DataProvider
The same procedure can be used if a common Data is to be used instead
of a common Presenter. In this case the method call must be set:
# Configuration/Services.yaml
services:
Vendor\Extension\DataProcessing\HighlightBoxProcessor:
tags: ['handlebars.processor']
calls:
- setProvider: ['@Vendor\Extension\Data\HighlightProvider']
Vendor\Extension\DataProcessing\HighlightTextProcessor:
tags: ['handlebars.processor']
calls:
- setProvider: ['@Vendor\Extension\Data\HighlightProvider']