symfony-cmf / tree-browser-bundle

Integrates javascript tree browser with PHPCR and PHPCR-ODM.
https://cmf.symfony.com
Other
22 stars 17 forks source link

[2.0] Usage without Doctrine ODM #145

Open iluuu1994 opened 7 years ago

iluuu1994 commented 7 years ago

We're using Gedmo Tree instead of Doctrine ODM for our tree data structure. In Version 1.0 of the TreeBrowserBundle it was pretty easy to write my own Tree class by implementing the TreeInterface.

How can I achieve the same thing now?

Thanks for your work!

wouterj commented 7 years ago

@iluuu1994 now, the resource packages are used for the backend. Resource is an abstraction of tree-based backends, built on top of Puli.

So to make this Gedmo Tree compatible, you have to create a GedmoTreeRepository. You can see the DoctrineOdm repository here: https://github.com/symfony-cmf/resource/blob/master/src/Repository/PhpcrOdmRepository.php

After that, you have to create a GedmoTreeRepositoryFactory for the interaction with the container: https://github.com/symfony-cmf/resource-bundle/blob/master/src/DependencyInjection/Repository/Factory/DoctrinePhpcrOdmFactory.php

Then in your bundle's build() method, add CmfResourceBundle::addRepositoryFactory(new GedmoTreeRepositoryFactory()); and enable the factory like: https://github.com/symfony-cmf/cmf-sandbox/blob/master/app/config/config.yml#L121-L123

So it involves some more things, but the good side of the story is that you have a nice abstraction for the tree that you can use throughout your application (so it's easy to switch to PHPCR ODM, file structure, XML, any tree like thing in the future for instance).

iluuu1994 commented 7 years ago

@wouterj Thanks for the thorough explanation! I'll let you know if I get it working. Would you be interested in merging the Gedmo adapter?

wouterj commented 7 years ago

Yep, I'm very interesting in supporting ORM in the Symfony CMF. Adding a Gedmo tree repository seems like a very nice step in this direction.

If you need any help creating the repository or pull request, feel free to join the #symfony_cmf channel on the Symfony slack and ping me (@wouterj).