Skip to content

XmlText Field Type

The XmlText Field Type isn't officially supported by eZ Platform. It can be installed by requiring ezsystems/ezplatform-xmltext-fieldtype. The Back Office does not support WYSIWYG editing of Fields of this type.

This Field Type validates and stores formatted text using the eZ Publish legacy format, eZXML. 

Name Internal name Expected input
XmlText ezxmltext mixed

Input expectations

Type Description Example
string XML document in the Field Type internal format as a string. See the example below.
eZ\Publish\Core\FieldType\XmlText\Input An instance of the class implementing the Field Type's abstract Input class. See the example below.
eZ\Publish\Core\FieldType\XmlText\Value An instance of the Field Type's Value object. See the example below.

Example of the Field Type's internal format

1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>
<section
    xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
    xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
    xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
    <paragraph>This is a paragraph.</paragraph>
</section>

For XHTML Input

The XML output uses <strong> and <em> by default, respecting the semantic XHTML notation.

Learn more about <strong>, <b>, <em>, <i>:

Input object API

Input object is intended as a vector for different input formats. It should accept input value in a foreign format and convert it to the Field Type's internal format.

It should implement the abstract eZ\Publish\Core\FieldType\XmlText\Input class, which defines only one method:

Method Description
getInternalRepresentation The method returns the input value in the internal format.

At the moment there is only one implementation of the Input class, eZ\Publish\Core\FieldType\XmlText\Input\EzXml, which accepts input value in the internal format, and therefore only performs validation of the input value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Example of using the Input object

...
 
use eZ\Publish\Core\FieldType\XmlText\Input\EzXml as EzXmlInput;

...

$contentService = $repository->getContentService();
$contentTypeService = $repository->getContentTypeService();
 
$contentType = $contentTypeService->loadContentTypeByIdentifier( "article" );
$contentCreateStruct = $contentService->newContentCreateStruct( $contentType, "eng-GB" );

$inputString = <<<EZXML
<?xml version="1.0" encoding="utf-8"?>
<section
    xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
    xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
    xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
    <paragraph>This is a paragraph.</paragraph>
</section>
EZXML;
 
$ezxmlInput = new EzXmlInput( $inputString );

$contentCreateStruct->setField( "description", $ezxmlInput );
 
...

Value object API

eZ\Publish\Core\FieldType\XmlText\Value offers the following properties:

Property Type Description
xml DOMDocument Internal format value as an instance of DOMDocument.

Validation

Validation of the internal format is performed in the eZ\Publish\Core\FieldType\XmlText\Input\EzXml class.

Settings

Following settings are available:

Name Type Default value Description
numRows int 10 Defines the number of rows for the online editor in the back-end interface.
tagPreset mixed Type::TAG_PRESET_DEFAULT Preset of tags for the online editor in the back-end interface.

Tag presets

Following tag presets are available as constants in the eZ\Publish\Core\FieldType\XmlText class:

Constant Description
TAG_PRESET_DEFAULT Default tag preset.
TAG_PRESET_SIMPLE_FORMATTING Preset of tags for online editor intended for simple formatting options.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// Example of using settings in PHP

...
 
use eZ\Publish\Core\FieldType\XmlText\Type;

...

$contentTypeService = $repository->getContentTypeService();
$xmltextFieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( "description", "ezxmltext" );

$xmltextFieldCreateStruct->fieldSettings = [
    "numRows" => 25,
    "tagPreset" => Type::TAG_PRESET_SIMPLE_FORMATTING
];
 
...