1

I've been trying to figure out how to create a base content type and subtypes (bundles) in Drupal 8, but haven't been able to figure it out.

For example:

Base Content Type

  • Base Event (fields: event name, start/end dates and times, location, etc.)

Subtypes (Bundles)

  • Seminar
  • Conference

I looked into:

  • ECK (Entity Construction Kit) module: didn't seem to be working 100% in Drupal 8. Using their example, I was able to create a 'Vehicle' ECK base type and 'Car' and 'Truck' ECK subtypes, but wasn't able to define any fields for the 'Vehicle' base type that would be shared between 'Car' and 'Truck'. Also, the types appeared under 'ECK Types' in 'Admin > Structure', so not sure if they would be usable throughout Drupal in the same way that regular Content Types are used/referenced?

  • Paragraphs module: doesn't seem to the right module for this

It looks as though I have to do this through code somehow, but couldn't find any clear documentation that explains step-by-step how to do this in Drupal 8.

Any help would be greatly appreciated. Thank you.

  • It should be called entity in Drupal. Base Content Type make me confused.... – Jimmy Ko Aug 3 '16 at 22:56
2

Creating entity is quite complicated, but it will be easier if you generate a base code with Drupal console command first.

drupal generate:entity:content [options]

Options

  • --module The Module name.
  • --entity-class The content entity class
  • --entity-name The content entity name
  • --base-path The base-path for the content entity routes
  • --label The label
  • --has-bundles Entity has bundles
  • --is-translatable Content entity translatable

I post some useful tutorial / documentation here:

  • Thanks for your prompt reply Jimmy. I appreciate it. Is there an article/link that explains the files that are generated and how to customize them? Thanks again! – kvjava1 Aug 3 '16 at 23:16
  • I have updated in answer. Drupal console only generate the scaffolding, its structure is quite similar to the example in documentation. – Jimmy Ko Aug 3 '16 at 23:28
  • 1
    Thanks again Jimmy! I will check out those links that you kindly provided. – kvjava1 Aug 3 '16 at 23:52
  • 1
    Sorry for the delay. Personal issues and other work pulled me away from working on this one. Your answer nicely describes how to create an entity, but how do you create sub-entities (like a subclass in Java), where the sub-entities share the common attributes of the parent (base) entity? Thanks again! – kvjava1 Dec 2 '16 at 5:24
  • @kvjava1 Why not just create different bundles of the entity? – Jimmy Ko Dec 2 '16 at 9:35

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.