Skip to content

Latest commit

 

History

History
153 lines (95 loc) · 4.57 KB

interpreter.md

File metadata and controls

153 lines (95 loc) · 4.57 KB

Interpreter

To prepare data before it goes to the Data Objects or your Export File, there are these "Interpreters"

Bundled interpreters

Here's a list of interpreters bundled with Data Definitions.

AssetByPath

Input - string with Pimcore path.

Returns an asset resolved using provided path.

AssetUrl

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.

AssetsUrl

Input - array.

Returns an array of assets or null. Each element of input array is interpreted by AssetUrl interpreter.

Carbon

Input - string

Returns null or Carbon object generated using provided format.

Checkbox

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.

Conditional

Input - any

Interprets an expression and redirects input into specified interpreters, based on the result of expression.

DefaultValue

Input - any

Returns string value passed in interpreter's configuration.

Definition

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.

DoNotSetOnEmpty

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.

Expression

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 - input
  • object - currently imported object (e.g. object.getProductName())
  • data - row of data being currently imported

Href

Input - string, int - an Id of a DataObject.

Returns DataObject of given id.

Iterator

Input - array

Runs given interpreter on each element of provided array. Returns the same array with it's elements modified by the interpreter.

Mapping

Input - string

Returns string value based on the provided mapping.

Metadata

MultiHref

Input - string, int - an Id of a DataObject.

Returns an array containing DataObject of given id.

Nested

Input - any

Passes input through a set of interpreters. Returns the value returned by the last interpreter in chain.

ObjectResolver

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.

QuantityValue

Input - string, int

Returns QuantityValue object with input as a value and with defined unit.

SpecificObject

Input - any

Returns DataObject specified in configuration.

Twig

Input - string

Returns output of the twig rendered using given template and provided input.

TypeCasting

Input - any

Returns input casted to a given type.

Creating your own interpreters

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'