Structured Data Fields - Fieldcollections

Skip to end of metadata
Go to start of metadata

Fieldcollection

Object field collections are predefined sets of data and layout fields, that can be added to objects at an arbitrary amount. There is a video available demonstrating object field collections:

An object field collection is very similar to an object itself, but with the difference that a field collection can not contain relation data types. It has a "class" or in this case "field definition" which needs to be made first, and then different field collection definitions can be used to add sets of fields to an object. So with some restrictions you could say, a field collection is an object within an object. When adding a field collection field to an object's class definition, the developer needs to specify the allowed field definition types for this field. The user can then decide which and how many of the available field definitions shall be added to the object.

Field definition data is stored in a separate table for each field definition and object class. The naming convention for these tables is: object_collection_COLLECTION-NAME_OBJECT-ID. Such a table contains all the field data, the concrete object's id, field name and index of of the field collection within the field collection data field. In order to fully understand the data structure of objects and field collections, it is best to enter some example data and have a look at the tables created by pimcore.

Of course, field collection data can be set programmatically as well. The following code snippet illustrates how this can be achieved. Let's say there is an object class "collectiontest" and a fieldcollection called "MyCollection". There is an object field called "collectionitems" which is of the type field collection.

        $object = new Object_Collectiontest();
 
        $object->setParentId(1);
        $object->setUserOwner(1);
        $object->setUserModification(1);
        $object->setCreationDate(time());
        $object->setKey(uniqid() . rand(10, 99));
 
        $items = new Object_Fieldcollection();
 
        for ($i = 0; $i < 5; $i++) {
            $item = new Object_Fieldcollection_Data_MyCollection();
            $item->setMyinput("this ist a test " . $i);
            $items->add($item);
        }
 
        $object->setCollectionitems($items);
        $object->save();

Inheritance

WARNING
Is not possible with this datatype.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.