Shared components¶
It is not always necessary or desired to automatically register all
related components based on the registration of a DataProcessor
.
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 DataProvider
or Presenter
for individual DataProcessors
in the Services.yaml
file.
Warning
Use of the AbstractDataProcessor
required
The following examples are only applicable to DataProcessors
that
extend the AbstractDataProcessor
, since it provides the necessary
methods. These are not part of the DataProcessorInterface
.
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 DataProviders
.
In the Services.yaml
file, we register both DataProcessors
, but
specify a concrete method call setPresenter()
. 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 DataProcessors
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 DataProvider
is to be used instead
of a common Presenter
. In this case the method call must be setProvider()
:
# 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']