0

I created a project using Content Entity but now I need to change this entity to Config Entity. Do you know how I can do this?

1
  • 1
    Can you give more details? Show what you've researched and/or coded so far. – Matt Aug 27 '20 at 22:12
2

ContentEntity and ConfigEntity are very different. My advice is to just start over.

4
  • To the person who downvoted this - how do YOU suggest the poster change content entity data in the database, including base field definitions, bundles, entity forms, etc. into Config? Have you ever tried this? While it's barely possible for a specific, simple case, it's not possible to do IN GENERAL - the data models are so very different that if you're planning to make this switch from Content to Config then you need to do a LOT of thinking and work to redefine what your data models and use cases are. The advice I gave is good; if you think I'm wrong then come out and state your reasons. – anonymous Aug 19 '20 at 0:23
  • 1
    Didn't downvote, but maybe add this explanation to our answer. – leymannx Oct 26 '20 at 20:13
  • 1
    Changing lead into gold is also possible (see en.wikipedia.org/wiki/Nuclear_transmutation) but the fact that it's possible does not mean that the best way to produce gold is to start with lead - it's not. Accept the answer or don't, this is not a grey area where various factors may influence the choice one way or another. If you've mistakenly programmed a ContentEntity and now want it to be a ConfigEntity, then the only choice IMO is to start over. – anonymous Oct 27 '20 at 22:37
  • 1
    I didn't ask that question. I'm just a moderator. – leymannx Oct 28 '20 at 7:02
2

Agreed with @anonymous: the structure and purpose of config entities is very different from content entities. Start with a clean config entity and only then see if you can reuse some of your existing code, most likely in the form functions, twig templating and ancillary CSS and JS files.

And if you're starting from scratch, definitely try Drupal Console if you haven't already. It will generate spotless boilerplate code specifically for a config entity:

drupal generate:entity:config
1
  • 1
    Drupal Console seems to be pretty inactive/abandoned and might still not be fully compatible with D9. But there also drush generate configuration-entity and drush generate content-entity. – leymannx Oct 26 '20 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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