Creating a render preprocessor
Render preprocessors are defined as Drupal RjsfRenderPreprocess
plugins in modules. To create your own preprocessor plugin:
- Navigate to the custom module that will contain your plugin
- Open or create
custom_module/src/Plugin/Rjsf/RenderPreprocess
- Create a new class
ExamplePlugin.php
- Extend
RenderPreprocessPluginBase
- Populate the annotation and
preprocess()
method
Example
Additional examples can be found in the RJSF module.
<?php
namespace Drupal\custom_module\Plugin\Rjsf\RenderPreprocess;
/**
* @RjsfRenderPreprocess(
* id = "example_preprocess",
* label = @Translation("Example preprocess"),
* )
*/
class ExamplePlugin extends RenderPreprocessPluginBase {
public function preprocess($value, array $vars = [], array $schema = [], array $uiSchema = []) {
// Do preprocessing logic here
$processed = '';
return $processed;
}
}
Arguments
value
This will contain the value of the property targeted in the renderPreprocess
part of a schema. Currently preprocessors do not have access to the complete form data but that may change in the future.
vars
Any vars defined with the plugin definition in a renderPreprocess
.
schema
The full schema definition.
uiSchema
The full uiSchema defintion.