To prepare data before it goes to the Data Objects or your Export File, there are these "Interpreters"
Here's a list of interpreters bundled with Data Definitions.
Input - string
with Pimcore path.
Returns an asset resolved using provided path.
Input - string
with url.
Returns an asset resolved using provided url or null
.
If asset with the same filename exists in the target folder - it will be returned instead.
Interpreter will try to get filename from Content-Disposition
headers. If they aren't provided by the server, url will be used to generate the filename.
If Deduplicate by url
option is used, Interpreter will try to find existing asset using url stored in it's metadata. Each asset downloaded by this interpreter will have this metadata.
Input - array
.
Returns an array
of assets or null
. Each element of input array is interpreted by AssetUrl interpreter.
Input - string
Returns null
or Carbon
object generated using provided format.
Input - any
Returns value interpreted as boolean
. For strings uses filter_var(strtolower($value), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
. For empty strings returns null
.
Input - any
Interprets an expression and redirects input into specified interpreters, based on the result of expression.
Input - any
Returns string value passed in interpreter's configuration.
Input - string
- name of the definition
Runs a separate import on the same dataset, with provided definition. Returns null
, imported DataObject
or array
of imported DataObjects
.
Input - any
Throws DoNotSetException
if input is empty or null
. Returns provided value.
Can be used to break a chain of nested interpreters or when emptying existing value is unwanted.
Input - string
Returns value interpreted by Symfony ExpressionLanguage engine (https://symfony.com/doc/current/components/expression_language.html).
In the expression it's possible to access all data available to the interpreter, among others:
value
- inputobject
- currently imported object (e.g.object.getProductName()
)data
- row of data being currently imported
Input - string
, int
- an Id of a DataObject
.
Returns DataObject
of given id.
Input - array
Runs given interpreter on each element of provided array
. Returns the same array with it's elements modified by the interpreter.
Input - string
Returns string
value based on the provided mapping.
Input - string
, int
- an Id of a DataObject
.
Returns an array
containing DataObject
of given id.
Input - any
Passes input through a set of interpreters. Returns the value returned by the last interpreter in chain.
Input - string
Searches for DataObjects
of given class, by given field, using input as a search query (getByField). Returns DataObject
if exactly one element has been found. Otherwise returns null
.
Input - string
, int
Returns QuantityValue
object with input as a value and with defined unit.
Input - any
Returns DataObject
specified in configuration.
Input - string
Returns output of the twig rendered using given template and provided input.
Input - any
Returns input casted to a given type.
Data Definitions provides you with a basic starting set of Interpreters, but you can create custom ones as well.
Todo that, you need to implement the interface Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface
and create a service
acme_bundle.data_definitions.my_interpreter:
class: AcmeBundle\DataDefinitions\MyInterpreter
tags:
- { name: data_definitions.interpreter, type: myinterpreter, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType }
If your Interpreter does have configuration as well, you need to create a new FormType and add a new Javascript file for the GUI:
pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.myinterpreter');
pimcore.plugin.datadefinitions.interpreters.myinterpreter = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, {
});
You also need to load your Javascript File in your config.yml
data_definitions:
pimcore_admin:
js:
my_interpreter: '/static/pimcore/myinterpreter.js'