Columns configuration

You also need an “external” syntax for each column to define which external data goes into that column and any handling that might apply. This is also an indexed array. Obviously indices used for each column must relate to the indices used in the “ctrl” section. In its simplest form this is just a reference to the external data’s name:

'code' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:externalimport_tut/locallang_db.xml:tx_externalimporttut_departments.code',
        'config' => array(
                'type' => 'input',
                'size' => '10',
                'max' => '4',
                'eval' => 'required,trim',
        ),
        'external' => array(
                0 => array(
                        'field' => 'code'
                )
        )
),

The properties for the columns configuration are described below.

Properties

Property Data type Step/Scope
attribute string Handle data (XML)
attributeNS string Handle data (XML)
disabledOperations string Store data
field string Handle data
fieldNS string Handle data (XML)
MM MM configuration Store data
transformations Transformations configuration Transform data
xmlValue boolean Handle data (XML)
xpath string Handle data (XML)

field

Type
string
Description

Name or index of the field (or node, in the case of XML data) that contains the data in the external source.

For array-type data, this information is mandatory. For XML-type data, it can be left out. In such a case, the value of the current node itself will be used, or an attribute of said node, if the attribute property is also defined.

Scope
Handle data

attribute

Type
string
Description

If the data is of type XML, use this property to retrieve the value from an attribute of the node rather than the value of the node itself.

This applies to the node selected with the field property or to the current node if field is not defined.

Scope
Handle data (XML)

xpath

Type
string
Description

This property can be used to execute a XPath query relative to the node selected with the field property or (since version 2.3.0) directly on the current node if field is not defined.

The value will be taken from the first node returned by the query. If the attribute property is also defined, it will be applied to the node returned by the XPath query.

Please see the namespaces property for declaring namespaces to use in a XPath query.

Scope
Handle data (XML)

fieldNS

Type
string
Description

Namespace for the given field. Use the full URI for the namespace, not a prefix.

Example

Given the following data to import:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
        <InvoiceLine>
                <cbc:ID>A1</cbc:ID>
                <cbc:LineExtensionAmount currencyID="USD">100.00</cbc:LineExtensionAmount>
                <cac:OrderReference>
                        <cbc:ID>000001</cbc:ID>
                </cac:OrderReference>
        </InvoiceLine>
        ...
</Invoice>

getting the value in the <cbc:LineExtensionAmount> tag would require the following configuration:

'external' => array(
        0 => array(
                'fieldNS' => 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
                'field' => 'LineExtensionAmount'
        )
)
Scope
Handle data (XML)

attributeNS

Type
string
Description
Namespace for the given attribute. Use the full URI for the namespace, not a prefix. See fieldNS for example usage.
Scope
Handle data (XML)

MM

Type
MM configuration
Description
Definition of MM-relations, see specific reference for more details.
Scope
Transform data

transformations

Type
array (see Transformations configuration)
Description

Array of transformation properties. The transformations will be executed as ordered by their array keys.

Example:

$GLOBALS['TCA']['fe_users']['columns']['starttime']['external'] = array(
                0 => array(
                                'field' => 'start_date',
                                'transformations => array(
                                                20 => array(
                                                                'trim' => true
                                                ),
                                                10 => array(
                                                                'userFunc' => array(
                                                                                'class' => \Cobweb\ExternalImport\Task\DateTimeTransformation::class,
                                                                                'method' => 'parseDate'
                                                                )
                                                )
                                )
                )
);

The “userFunc” will be executed first (10) and the “trim” next (20).

Scope
Transform data

xmlValue

Type
boolean
Description
When taking the value of a node inside a XML structure, the default behaviour is to retrieve this value as a string. If the node contained a XML sub-structure, its tags will be stripped. When setting this value to true, the XML structure of the child nodes is preserved.
Scope
Handle data (XML)

disabledOperations

Type
array
Description

Comma-separated list of database operations from which the column should be excluded. Possible values are “insert” and “update”.

See also the general property disabledOperations.

Scope
Store data