DataSourceAwareProcessor
Implement the
\CPSIT\Typo3Handlebars\DataProcessing\DataSource\DataSourceAwareProcessor
interface to run custom PHP logic during the
pre or
post stages of a
process-
processor (or of
HANDLEBARSTEMPLATE directly). Unlike standard
TYPO3 data processors, implementations receive a
Data
that gives structured access to all four data sources available at that point
in the pipeline.
- interface DataSourceAwareProcessor
-
- Fully qualified name
-
\CPSIT\
Typo3Handlebars\ Data Processing\ Data Source\ Data Source Aware Processor
- process ( array $variables, DataSourceCollection $collection, ContentObjectRenderer $contentObjectRenderer)
-
Process the current variable set and return the (modified) array.
- param array $variables
-
Current template variable set.
- param DataSourceCollection $collection
-
All four data sources for the current rendering.
- param ContentObjectRenderer $contentObjectRenderer
-
Current content element renderer.
- returntype
-
array
Reading from DataSourceCollection
Data searches the data sources in priority
order and returns the first match. Pass a specific
Data case to
restrict the lookup:
use CPSIT\Typo3Handlebars\DataProcessing\DataSource\DataSource;
// Search all sources (highest priority first)
$table = $collection->resolve('table');
// Search only the processor configuration
$table = $collection->resolve('table', DataSource::ProcessorConfiguration);
// Search two specific sources, in the given order
$table = $collection->resolve('table', [
DataSource::ProcessorConfiguration,
DataSource::ContentObjectConfiguration,
]);
The four
Data cases are:
Data— this processor's own config blockSource:: Processor Configuration Data— accumulated output from previous processorsSource:: Processed Data Data— current record's field valuesSource:: Content Object Renderer Data— top-levelSource:: Content Object Configuration HANDLEBARSTEMPLATEconfig
Example implementation
namespace Vendor\Extension\DataProcessing;
use CPSIT\Typo3Handlebars\DataProcessing\DataSource\DataSource;
use CPSIT\Typo3Handlebars\DataProcessing\DataSource\DataSourceAwareProcessor;
use CPSIT\Typo3Handlebars\DataProcessing\DataSource\DataSourceCollection;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
final readonly class MyPreProcessor implements DataSourceAwareProcessor
{
public function process(
array $variables,
DataSourceCollection $collection,
ContentObjectRenderer $contentObjectRenderer,
): array {
$table = $collection->resolve('table', DataSource::ProcessorConfiguration, 'tt_content');
$variables['tableName'] = $table;
return $variables;
}
}
Registering the processor
Reference the processor class by its fully qualified class name in
pre or
post:
10 = process-variables
10 {
variables {
header = TEXT
header.field = header
}
preProcessing {
10 = Vendor\Extension\DataProcessing\MyPreProcessor
}
}
The numeric keys control execution order when multiple processors are
registered. The class is instantiated via
General, so constructor injection works
as normal.