1

I am trying to recreate the functionality of a NodeType/Node entity at a basic level.

I want to define entity types (FooType) which can be fielded individually, just like NodeType can be.

I used the Drupal Console to generate a config entity and content entity. Out of the box, it creates types and content entities of those types. However you can't field those types, I don't see a way to add that.

When I try to mimic the annotation in NodeType to allow fields, I get the following error when I try to save a field to a FooType:

Missing bundle entity, entity type foo_type, entity id foo.

Where am I going wrong? Is this something the Drupal Console can already do and I missed it?

Update:

So I think I am past the original issue... now when I want to add a field on a type, I get:

Attempt to create a field 'field_testfield' without a bundle.

The URLs don't seem to be correct, as it keeps dropping me back on Foo entity settings instead of stay within FooType, where I am trying to add fields to.

  • Too few specifics/details to answer this. Note that bundles are not required to have configurable fields (e.g. user doesn't have bundles). In that case, bundle == entity_type_id. The only relevant connection between Node and NodeType is an annotation key pointing to the other one on each entity annotation. Post those and we might be able to help. – Berdir Nov 4 '15 at 21:41
  • Why would you want to have entity types that cannot be fielded by default? Even if you don't have plans on fielding them, the option is there. It was easy to enable this in EntityAPI in D7, but took a bit more work to get it going with code generated from Console. – Kevin Nov 6 '15 at 14:53
  • 1
    Again, they are fieldable without bundles, just only one variant of fields. And I'd say when you generate your own custom entity types, then it's quite likely that you don't need bundles nor configurable fields because you're going to add the specific fields that you need for your use case as base fields? Anyway, if you want to see improved support for this, then you need to open an issue in the console issue queue. – Berdir Nov 6 '15 at 15:05
0

I eventually got it by comparing how NodeType/Node is defined:

http://cgit.drupalcode.org/user_alert/tree/src/Entity?h=8.x-1.x

Now I can have unlimited entity types and add fields to them for different content configurations of the entity.

I started out by generating a config and content entity with the Console, but found that in order to get a more intuitive user interface, I had to modify the routing.yml and some of the paths as well.

Just a note for those looking for the same functionality.

  • Do you have a more extensive write-up on this? – Patrick Jun 15 '17 at 5:44

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.