Serialized Fields 

OroPlatform provides the ability to create custom entities or custom fields for extended entities. This package provides a possibility to avoid schema update when you create custom fields.

However, these fields have some restrictions. Their data is stored in the serialized_data column as a serialized array but the serialized_data field is hidden from the UI on entity config page.

Not supported features:

  • grid filtering and sorting

  • segments and reports

  • charts

  • search

  • relations, enums, and option set field types

  • data audit

  • usage of such fields in Doctrine query builder

Serialized Fields Access

Serialized fields are available as public class properties and handled by magic __get and __set methods in the entity. There are, therefore, no getters and setters for these fields.

The Serialized Fields bundle adds a new field called Storage Type within New field creation page where you need to choose one of the two storage types:

  • The Table Column option enables to create custom field as usual;

  • The Serialized field option means that you can avoid schema update and start to use this field immediately. Keep in mind that in this case field types are limited to the following:

    • BigInt

    • Boolean

    • Date

    • DateTime

    • Decimal

    • Float

    • Integer

    • Money

    • Percent

    • SmallInt

    • String

    • Text

    • WYSIWYG

Basic properties available when creating a new field for an entity

To create a serialized field via migration, use SerializedFieldsExtension. For example:

src/Acme/Bundle/DemoBundle/Migrations/Schema/v1_4/AddSerializedFieldMigration.php 
<?php

namespace Acme\Bundle\DemoBundle\Migrations\Schema\v1_4;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
use Oro\Bundle\EntitySerializedFieldsBundle\Migration\Extension\SerializedFieldsExtension;
use Oro\Bundle\EntitySerializedFieldsBundle\Migration\Extension\SerializedFieldsExtensionAwareInterface;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddSerializedFieldMigration implements Migration, SerializedFieldsExtensionAwareInterface
{
    protected SerializedFieldsExtension $serializedFieldsExtension;

    /**
     * @inheritDoc
     */
    public function setSerializedFieldsExtension(SerializedFieldsExtension $serializedFieldsExtension)
    {
        $this->serializedFieldsExtension = $serializedFieldsExtension;
    }

    /**
     * @inheritDoc
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        $this->serializedFieldsExtension->addSerializedField(
            $schema->getTable('acme_demo_document'),
            'my_serialized_field',
            'string',
            [
                'extend'    => [
                    'owner' => ExtendScope::OWNER_CUSTOM,
                ],
                'entity' => ['label' => 'My serialized field'],
            ]
        );
    }
}

Serialized files support the same set of config options as other configurable fields.

Business Tip

The upcoming frontier of eCommerce is B2B marketplaces. Discover how a business-to-business marketplace can help digitally transform your company.