Vous êtes sur la page 1sur 1

Entities and Bundles in Drupal 7 (presented in the least confusing way I could manage)

Entity w/ No Bundles
Node Extends Entity users
Instance of Node create
more
Entity Class instances ...
Properties
No fields

Provided by core
Fieldable = False
This is the most basic case of an Entity. The Entity defines
Bundles = Array()
Content
no bundles so it presents only one type that can be
instantiated. Also, this Entity is defined as not field-able, so
the Field API cant be used to add fields to it with the
Drupal Admin Interface.
Node Controller
EntityAPIController Instance of Node
extends
Class Controller
EntityAPIController

Database

EntityAPIController
Class
Entity w/ 2 Defined Bundles
Node Controller
Node Extends Entity Instance of Article users extends
(node) create EntityAPIController
more
Entity Class
Properties
No fields instances ... This takes it to the next step. The Entity defines 2 bundles
Instance of Node
called Article and Story. Both of these bundles define a
Fieldable = False Content
Provided by core
Bundles Array
Controller
type of Node Entity that can be instantiated. This still does
Article (no fields)
not allow Fields to be added.
Story (no fields) users
Instance of Story
(node) create
more
instances ... Database

No fields

Content

EntityAPIController
Class
Entity w/ Bundles and Fields
Node Controller
Node Extends Entity Instance of Article users extends
(node) create
more
EntityAPIController This is the same as the previous example except now the
Entity Class
Properties
User defined fields instances ... Field-able attribute is set to TRUE. This means that now
Fieldable = True Content
Instance of Node the Field API can customize the two bundles with custom
Controller
Provided by core
Bundles Array field sets defined by the user via the administration
Article (yes fields) interface (or by a custom module).
Story (yes fields)
Instance of Story users
(node) create
more
User defined fields instances ... Database

Content

Bundles of Node Entity defined by and


Entity w/ N Bundles and Fields
instantiated by users
EntityAPIController
Node Extends Entity Instance of Article users Class This is the step that confused the squeeze out of me, and I
create
(node)
more think the one that drive all the What is an Bundle
Entity Class
Properties User defined fields
instances ...
Node Controller
questions. In a lot of the documentation it doesnt seem
extends
EntityAPIController
like it is specified which use case the articles are talking
Provided by core
Fieldable = True Content
about.
Bundles Array

Defined by instances
Instance of Node
So the answer to the question Is a Bundle a sub-type of an
of NodeType Entity
Instance of Story users Controller Entity? is YES!
(node) create
more
User defined fields instances ... But... the answer to the question Is a Bundle an Entity? is
also Probably! (depending on how the Entity in question is
Content
via entityAPI Database
defined.)
hook_entity_info_alter
So in this example we add a new super power to Entities
users create more
bundles via the via the Entity API. In the previous example we were limited
NodeType Entity
to adding Fields to Bundles that the developer of the Entity
. defined for us.
.
.
But, now because the Bundle Array in the Node Entity is
populated dynamically by the Entity API with the Instances
of the NodeType Entity we can define any number of
Bundles for the Node Entity that we wish :)
Bundles of Node Entity

NodeType Extends Entity Instance of Instance of


NodeType NodeType
users
Entity Class create
Fields (inherited Fields
Text(inherited
Properties more
from Node) from Node)
instances
Provided by (ie bundles)
Fieldable = False
core Label: Article Label: Story
Bundles = Array()
...
Bundle of = Node

Instance of
NodeType Controller
Node Controller
EntityAPIController
extends
Class
EntityAPIController

Database

by Ntrepid8 via http://joshaust.in

Friday, June 22, 12

Vous aimerez peut-être aussi