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

Overriding Object Datatypes #4679

Closed
bebuecherl opened this issue Jul 12, 2019 · 1 comment
Closed

Overriding Object Datatypes #4679

bebuecherl opened this issue Jul 12, 2019 · 1 comment

Comments

@bebuecherl
Copy link
Contributor

bebuecherl commented Jul 12, 2019

Bug Report / Discussion

I'm currently working on overriding a Pimcore default Object Datatype (Localizedfields), as a customer of ours needs #2958 and we wanted to have it configurable (which Languages are mandatory and which are not). So I followed the instructions in the docs to override the Datatype.

Expected behavior

Using either

pimcore:
    objects:
        class_definitions:
            data:
                map:
                    localizedfields: \AppBundle\Model\DataObject\ClassDefinition\Data\Localizedfields

or

pimcore:
    objects:
        class_definitions:
            data:
                prefixes:
                    - \AppBundle\Model\DataObject\ClassDefinition\Data\

results in registering/overriding the Datatype.

Actual behavior

Still uses the Pimcore Datatype when editing/saving ClassDefinitions in the backend.

As it looks to me, in PimcoreCoreExtension the prefixes are added as second loader to the ImplementationLoader. Since ImplementationLoader does reverse the array of loaders, it will start by using the PrefixLoader. This loads the prefixes in order. This means he will load all classes from \Pimcore\Model\DataObject\ClassDefinition\Data\ (config/default.yml) first; no matter what is defined in pimcore.objects.class_definitions.data.map.

I think this should be the other way arround, so the direkt mapping (pimcore.objects.class_definitions.data.map) is loaded before the glob mapping (pimcore.objects.class_definitions.data.prefixes). And maybe additionally reverse the prefixes, so custom configuration will be used before default (Pimcore) configuration

Steps to reproduce

(see description & expected behavior)

Current workaround

Inside my \AppBundle\DependencyInjection\AppExtension load-Method:

$prefixes = [ '\\AppBundle\\Model\\DataObject\\ClassDefinition\\Data\\' ];

$container->setDefinition(
    'pimcore.implementation_loader.object.data.prefix_loader',
    new Definition(PrefixLoader::class, [ $prefixes ])
);

$config = $container->getParameter('pimcore.config');

$config['objects']['class_definitions']['data']['prefixes'] = $prefixes;

$container->setParameter('pimcore.config', $config);

this will override the internal PrefixLoader when Containers are merged. (Also ensuring that the container configuration is correct).

@brusch
Copy link
Member

brusch commented Jul 24, 2019

Overriding data-types is not possible as it has a big potential that something massively breaks.
Best practice is to create your own data-type that extends existing data-types.

@brusch brusch closed this as completed Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants