The document discusses various concepts related to entities in Drupal 7 including:
1) Declaring an entity using hook_entity_info() and specifying the controller class.
2) Implementing hook_schema() to define the entity's database table.
3) Additional functionality provided by the Entity API module including entity properties and wrappers.
4) Using the entity class and controller for common operations like loading and saving entities.
5) Performing queries on entity fields using the EntityFieldQuery class.
2. About me
Senior LAMP developer at Pitech+plus
Drupal projects worked on:
http://www.louvre.fr
http://www.cartier.us
Module contributor:
Taxonomy revisions: http://drupal.org/project/taxonomy_revision
Maxlength widget for textareas: http://drupal.org/project/maxlength_js_widget
drupal.org profile:
http://drupal.org/user/350126
IRC nickname: skipyT
Twitter: @ztasnadi
3. Summary
short introduction to entities
declaring an entity
entity API
entity properties
fieldable entities
entity metadata wrappers
entity class and the entity controller
entity field queries
4. Entities
What is an entity?
A data unit!
A data unit which Drupal is aware of!
Stored Anywhere...
Entities in core:
node = entity content type = bundle
taxonomy term = entity vocabulary = bundle
and others like files, vocabularies.
5. Introduction to Entities
All of the entities are:
Loadable
Identifiable
Can be stored anywhere.
Also they can be fieldable.
10. Declaring an entity
And now you can use functions from core like:
entity_load();
entity_get_info();
entity_get_controller();
But this is not enough!
Let's check Entity API...
11. Entity API
Assists us interacting with entities.
entity_create()
entity_access()
entity_view()
entity_save()
entity_delete()
entity_load_single()
entity_get_property_info()
entity_metadata_wrapper()
12. Entity API
Provides a base entity class and a
base entity controller class.
Entity
EntityAPIController
Supports revisions, database
transactions, methods for create,
delete, load, etc.
Provides unified CRUD interface
14. Fieldable entities
Entities are fieldable if we set:
'fieldable' = TRUE,
//in hook_entity_info()
Bundles are like content types for nodes
Check the entity bundle plugin also:
http://drupal.org/project/entity_bund
le_plugin
15. Entity properties
Unified access to entity data
Validation
Access information
Several contrib modules are using it:
Entity views
Rules
Entity tokens
Search API
WSClient
VBO, OG, Drupal commerce
19. Entity class
We can use the entity class methods
to avoid to introduce new
implementations for:
hook_entity_presave
hook_entity_insert
hook_entity_update
Or to do custom methods like entity
health check, tagging, etc.
20. Entity controller
Example of usage:
During hook_cron we want to update,
touch multiple entities.
Don't forget to call the resetCache
and the mark to reindex if you are
updating the entities. Good example
is when you are enabling several
entities based on their publication
date.