1

Is it possible to use custom entity storage per bundle? Let's say I have node (entity type) which is called article (bundle). I want to store articles in different storage engine than every other nodes (like recipes). So far I have found no way to store single bundle in different storage engine. I could create custom entity type with custom bundle (that works, yes) but I really would like to use nodes and specify custom storage engine for one of them.

1 Answer 1

2

I'd strongly recommend against doing that. That's what separate entity types are for, bundles are just variations with different settings/configurable fields.

The assumption in many places is that all entities of a type a stored in the same places, for loading, querying and so on.

You could probably make it work by replacing the storage and have every relevant method (save, delete, load, query, ...) branch of into two different methods. Very likely more work and more complicated than just doing this for a separate entity type. and some things are impossible to get right (e.g. doing queries against a field shared by multiple bundles. core expects that to work).

2
  • Well, the problem is, that we are using D8 distribution (github.com/BurdaMagazinOrg/thunder-distribution) and we simply want to store article nodes to some other centralized content storage system (we strictly don't want them in Drupal DB). By creating custom entity type we lose pretty much everything for what we are using that D8 distribution. At the moment the only solution for me is to patch Node class inside namespace Drupal\node\Entity and change its storage engine...
    – rthideaway
    Aug 2, 2016 at 10:05
  • I forgot to mention, that if Node storage would be swappable at least, for now this would be enough. But I did not even found a way to swap Node storage, without dirty patching and changing the storage inside Node class...
    – rthideaway
    Aug 2, 2016 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.