Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataObject] allow data tags to be loaded via DI #4390

dpfaffenbauer opened this issue May 17, 2019 · 0 comments


None yet
1 participant
Copy link

commented May 17, 2019


First Problem: __set_state

Pimcore already allows to implement custom implementation loaders, which is good. That already basically allows to to implement Implementation Loaders from DI. The Problem with that is, how Pimcore stores ClassDefinitions. They are saved as PHP Classes, but it does it by using var_export, which creates files like that:

 'allowEmpty' => false,
 'model' => 'CoreShop\\Component\\Core\\Model\\Country',
 'params' => 
array (
 'fieldtype' => 'coreShopCountry',
 'options' => NULL,
 'width' => '',
 'defaultValue' => NULL,
 'optionsProviderClass' => NULL,
 'optionsProviderData' => NULL,
 'queryColumnType' => 'varchar',
 'columnType' => 'varchar',
 'columnLength' => 190,
 'phpdocType' => 'CoreShop\\Component\\Core\\Model\\Country',
 'name' => 'country',
 'title' => 'Country',
 'tooltip' => '',
 'mandatory' => false,
 'noteditable' => false,
 'index' => false,
 'locked' => false,
 'style' => '',
 'permissions' => NULL,
 'datatype' => 'data',
 'relationType' => false,
 'invisible' => false,
 'visibleGridView' => false,
 'visibleSearch' => false,

In here, you then already create the data tag:

Which is wrong when you wanna use Dependency Injection.

Second Problem: var_export

The definitions are created using var_export. Which is fine for now, since the Data Tags don't have any non scalar properties. But: Once you start using DI, they will and have. var_exports exports the whole object, even private and protected properties.

Current solution to use DI is a tricky one:

public function __construct(EntityManagerInterface $entityManager) 

private function entityManager(EntityManagerInterface $newValue = null)
    static $value;
    if ($newValue !== null) {
        $value = $newValue;
    return $value;



Possible Solutions

Wrong but easy solution

public static function __set_state($data)
    $thing = \Pimcore::getContainer()->get('')->build($data['fieldtype'], $data);
    return $thing;

Right but more complex solution

Don't use var_export to save Pimcore Class Definitions. You still can use PHP Files, but they should be in a format that will be parsed from Pimcore. Sort of like it was years ago. You could potentially also use the JSON Format for storage that is also used for exports. I would prefer YML or XML that can be validated against something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.