Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Jaypan on
I'm having troubles wrapping my head around the concept of 'bundle'. I've read about it in the D7 books I've got, but I still don't really understand what they are conceptually. Can anyone elaborate on this and/or provide some links to something with more of an explanation on the matter?
Comments
_
It's my understanding that a bundle is the collection of fields that belong to a particular entity -- but i'll see if i can find the exact definition i stumbled across.
I've been doing a bunch of
I've been doing a bunch of searching, the best thing I've come up with is that as a node is a type of entity, a content type is a type of bundle. Which actually makes a lot of sense to me!
_
It's actually in the d7 module dev book (check the index for the page)-- the best analogy I can think of is content type is to node as bundle is to entity. In other words, entities can have different types (like content types in d6) but they're called bundles.
does that make sense? it finally clicked for me last night when I looked it up.
Yeah it makes sense to me. I
Yeah it makes sense to me. I guess it's a sub-type of the entity. in OOP languages it would be a sub-class/derivative of the main class.
I'm putting together my first entity based module, so I was having some troubles wrapping my head around how to work with the bundles. I have a better idea now, but I've still got a ways to go.
My understanding
I've been reading some stuff and confused also. Best I can make out is
entity => is like a bank sheet with a name only... so could potentially be anything , map , calculations, users, content-type
field => field api stuff body,custom fields,images etc
bundle => entity + fields
instance => being viewed or used??
anyway thats how I see it atm but I'm not sure....
That looks pretty good,
That looks pretty good, except that some bundles may not have fields (if the entity isn't fieldable). But bundles may have variations of something different from each other. For example, I'm building an entity right now that is an email account - maybe one bundle would be pop3, and another would be imap.
What about: entity describes
What about: entity describes base object ( with its fields and behaviour ) and bundle adds some flavour to specific to particular type
For example:
one of the entities is: node
and there are different bundles like: blog, book
so all bundles get all fields defined in node entity ( like title, body, uid etc ) but specific bundle can have additional fields
I hope I got it right ;)
field as classinstance as
field as class
instance as object of the class instantiated
In php perspective
instance is configured field with real world parameters. field as a template for the instance
2 questions about bundles
I am totally unable to understand bundles and entities, if someone could answer the following questions that would help me, and maybe other people with the same problem.
The questions are:
1) do all the bundles belonging to an entity must have the same set of fields?
That would seem stiff but in the example I find in "Drupal 7 module development" I see only one DB table for an entity and 2 bundles in the entity.
2) if an entity has N bundles will an instance of the entity contain an instance of each bundle or only one instance of one of the bundles? Ie, if the N bundles have each 3 fields, will the entity instance contain 3*N fields or 3 fields?
1) Yes and no - I believe
1) Yes and no - I believe they should all have the same fields as the parent, but then may add their own fields that may be different from other bundles.
Ex:
Entity - car.
Bundles - 4-door and 2-door.
The two bundles have different fields (the number of doors), but both have an engine and a body.
2) Instances will be of the bundle, not the entity.
Disclaimer: I think.
Bundles are to Entities what
Bundles are to Entities what Content types used to be to Nodes in D6.
So now Node is just one type of entity and node types are called bundles.
If you make your own entity, let's call it "computer" for example, then you could make "computer types"(bundles), like Laptop, Desktop, HTPC, etc.
All entities can be made fieldable, so you can attach fields to them just like CCK used to do to node types.
Instance is what single node used to be, so it's single instance of your bundle with it's unique ID.
edit: Not to be mixed with Field API's 'field instance' which is one field attached to a bundle.
druid.fi
Very good! Now reread this
After reading what bfr explains reread this and it all seems to fit together nicely:
https://www.drupal.org/node/1261744
Fieldable-ness?
So when I hear an entity is 'fieldable', it means that I can add fields to it via the GUI and create a bundle. Meaning all the base fields of the entity must be declared in the hook_schema?
I was hoping to make an entity with only a primary id via schema and add the rest of the fields via the guy. But that seems like it is not what is envisioned for entities in D7. Is my reading correct in this? I need a well planned base entity and then bundles are like child classes, if I ever need those? Or can I just do a simple entity and make EVERYTHING a bundle by adding fields? Can I make a bundle from a bundle?
A Picture
I'm trying to make a good picture that shows what Entities and Bundles are in Drupal 7 and how they relate to each other (depending on the use case). I want to make sure this picture is accurate so please take a look at it here:
http://joshaust.in/2012/06/entities-and-bundles-in-drupal-7/
If anything is inaccurate please let me know in the comments so I can get it right.
http://drupal.org/node/126174
http://drupal.org/node/1261744
Wish: Bundles from Bundles = inheriting ContentTypes
Thanks for the link.
So when a Node is an EntityType and
Article in a ContentType = a bundle = an implementation of a Node, then I could wish to be able to create a bundle of a bundle e.g.
a MagazineArticle as a ContentType inheriting from Article ContentType.
Are the any modules providing that?
Bundles of bundles do not
Bundles of bundles do not exist in Drupal 7.
_
no but https://drupal.org/project/bundle_inherit is pretty cool ;-)
Every entity has a bundle
In your picture you have a 'Entity w/ No Bundles' section.
An example of that is the 'user' entity. This is an entity with no bundles..
Actually its not, the bundle of the 'user' entity is 'user' entity itself.
A nice explication !
Here you have a explication of entity and bundles.
http://drupal.org/node/1649688
See you
Miguel
Examples
Examples:
Entity type: Nodes (content), Comments, Taxonomy terms, User profiles
Bundle names: Pages, Articles, Blog Posts (Note: Not all entity types have bundles).
Read more:
An Introduction to Entities
Bundles are groups of fields
Bundles are groups of fields. A bundle is a specialisation, an instance of an entity. If node is an entity, then an article is an bundle. This allows distinguishing the kinds and types within the system - kinds classify types, types classify values (concrete objects)