I want an entity where I can store various bits of data (using fields) and link that data to multiple page nodes. But that data should not be visible to anyone - it is more for adding and displaying data programmatically or via Views. What's the best way to go about this?
I don't want to create a new node bundle to store data and link that to page nodes as that will also create a page for the new bundle etc. I'm thinking using Paragraphs is the best way to do this? Create a new Paragraph type, create the new paragraph field on the node that uses that paragraph type (hiding that field in node edit and display), then create the paragraph programmatically and link it to the node.
Is there a better way? Is creating a custom entity the more Drupal way to store data like this?
Hope that makes sense.
Comments
It seems, you may try the
It seems, you may try the 'ECK' module, but the use case is not entirely clear for me. Could you provide more info about the real use case?
I've always wondered...
Is the 'ECK' module a viable solution for a production Drupal 8 site?
I've always wondered if I should be creating my own entity type for such things or carry on using Paragraphs because it seems like the easier option - though I always want to do things the Drupal way.
I have a node type, lets call it 'thingy-ma-jig'. That node has an email field. I have an admin form where a user chooses from a list the thingy-ma-jig nodes they want to include in the process. On form submit, a batch operation runs doing various tasks. It is the data from those batch tasks that I want to store and link to the chosen nodes. Currently, I would create a new Paragraph storing the data of the task in various fields, then link that single new Paragraph to the chosen nodes as a single multi field on those nodes. I would then hide the paragraph from node edit/view so the data is kept internal. I can then use that data in various views etc for certain roles. Should I be creating a new entity instead of using Paragraphs, do you think? Is that a cleaner solution, even though it would be doing the same thing as a custom entity?
I guess I'm asking... is it OK to use Paragraphs to store data this way rather than what the module was intended... to help split content on a node?
I don't see the problems with
I don't see the problems with your approach.
Also, the patch from here may be useful, if you will try to get a node fields from a views that display paragraphs: https://www.drupal.org/project/entity_reference_revisions/issues/2799479
Thanks
Your answer is good enough for me. I'll keep using Paragraphs. Thanks for the link, I've followed the the issue 👍