eZ Community » Forums » eZ Publish 5 Platform » Create content with Matrix FieldType
expandshrink

Create content with Matrix FieldType

Create content with Matrix FieldType

Thursday 24 April 2014 8:09:12 pm - 10 replies

Hi,
I am working on a script which parse an XML File and creates content in database.
I have a problem with the Matrix fieldtype with the setField method, I don't know what kind of value it accepts ?

Any help please ?

Friday 02 May 2014 11:18:21 am

I think Matrix Fieldtype is not yet impelemented in eZ5.

see : eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtypes.yml

 

# Not implemented fieldtypes

ezpublish.fieldType.ezmatrix:

Friday 02 May 2014 4:18:25 pm

this is more an more common, apparently...

 

ez is working on a final version of the datatype. i'll check if we can give out anything "beta"

Friday 02 May 2014 6:51:06 pm

Ok thanks All.

Monday 04 August 2014 5:54:36 pm

Hi. Any progress on this? Anything beta available? 

Cheers.

Thursday 07 August 2014 11:41:44 am

+1

i think, this one is a important field...

cheers

Monday 18 August 2014 6:52:24 pm

Hi,

Also interested in being informed about ez5 implementation of Matrix datatype.

Thanks,

Irma

Tuesday 07 October 2014 7:16:55 am

The reply has been removed because of violation of forum rules.

Tuesday 07 October 2014 8:55:18 pm

Spam aside, alpha version of this fieldtype was released some time ago at: https://github.com/ezcommunity/EzMatrixFieldTypeBundle

Should be more then stable enough to make sure you avoid issues when this is used, however details on how the data is displayed and the api for dealing with it might change before it is final.

Modified on Tuesday 07 October 2014 9:07:42 pm by André R

Thursday 09 October 2014 8:57:27 am

I found a quickly solution.
In your boundle you must create a convert class for ezmatrix datatype

namespace <your vendor>\<name your bundle>\Converter;
 
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
use eZ\Publish\SPI\Persistence\Content\FieldValue;
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
 
class EzMatrix implements Converter
{
    public static function create()
    {
        return new self;
    }
 
    public function toStorageValue( FieldValue $value, StorageFieldValue $storageFieldValue )
    {
        $storageFieldValue->dataText = $value->data;
        $storageFieldValue->sortKeyString = $value->sortKey;
    }
 
    public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue )
    {
        
        $doc = new \DOMDocument( '1.0', 'utf-8' );
        $doc->loadXML( $value->dataText );
        
        $__MATRIX = array();
        
        $__MATRIX['NUMBER_COLUMNS'] = $doc->getElementsByTagName('columns')->item(0)->getAttribute('number');
        $__MATRIX['NUMBER_ROWS'] = $doc->getElementsByTagName('rows')->item(0)->getAttribute('number');
        
        $__MATRIX['COLUMNS_TITLE'] = array();
        $__MATRIX['COLUMS_TITLE_IDENTIFIER'] = array();
        
        $__COLUMNS = $doc->getElementsByTagName('column');
        
        foreach($__COLUMNS as $__COL)
        {
            $__MATRIX['COLUMNS_TITLE'][] = $__COL->nodeValue;
            $__MATRIX['COLUMS_TITLE_IDENTIFIER'][] = $__COL->getAttribute('id');
        }
 
         $__ROW_NUMBER = 0;
         $__COL_NUMBER = 0;
         
         $__MATRIX['ROWS'] = array();
         $__MATRIX['ROWS'][$__ROW_NUMBER] = array();
        
         $__ROWS = $doc->getElementsByTagName('c');
        
        foreach($__ROWS as $__KEY => $__ROW)
        {
            $__MATRIX['ROWS'][$__ROW_NUMBER][$__MATRIX['COLUMS_TITLE_IDENTIFIER'][$__COL_NUMBER]] = $__ROW->nodeValue;
            
            $__COL_NUMBER += 1;
            
            if ( ((($__KEY + 1) % $__MATRIX['NUMBER_COLUMNS']) === 0) && ( ($__KEY + 1) < $__ROWS->length))
            {
                $__MATRIX['ROWS'][] = array();
                $__ROW_NUMBER += 1;
                $__COL_NUMBER = 0;
            }
        }
 
         $fieldValue->data = $__MATRIX;
         $fieldValue->sortKey = $value->sortKeyString;
    }
    
    public function toStorageFieldDefinition( FieldDefinition $fieldDef, StorageFieldDefinition $storageDef )
    {
    }
 
    public function toFieldDefinition( StorageFieldDefinition $storageDef, FieldDefinition $fieldDef )
    {
    }
 
    public function getIndexColumn()
    {
        return false;
    }
}

Always in your bundle, under Resources/config file services.yml define your convert service for ezmatrix fieldtype

     ezpublish.fieldType.ezmatrix.converter:
            class: <your vendor>\<name your bundle>\Converter\EzMatrix
            tags:
                - {name: ezpublish.storageEngine.legacy.converter, alias: ezmatrix, lazy: true, callback: '::create'}

fieldtype exmatrix is just define as FieldType Null on Ez/Publish/Core/settings/fieldtypes.yml

This solution permet you to use ezmatrix datatype as fieldtype Array of Array in your twig template

Modified on Thursday 09 October 2014 12:39:27 pm by Pierandrea Della Putta

Thursday 09 October 2014 9:14:13 am

As ezsystems has made this public, my fork of this has became public too. in case anyone may find it useful, here is the link https://github.com/crevillo/MatrixFieldTypeBundle

Actually i'm working with this version for a own project and at least does the job. 

The plan is start sending to emit pull request to ezsystems repo so ez systems can take a look. But if anyone want give a try on mine version, go ahead happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from