SlideShare a Scribd company logo
Synapse India Reviews on 
Entities in Drupal 7 
& the Entity API
About Me 
 Founder & Chief Solutions Architect 
@ Modern Biz Consulting in Oakland 
 Strong development background 
 Working with Drupal since 2006 
 Developer, architect, project manager 
 Focus on complex web application development
Agenda 
 Ways we represent data in D6 vs D7 
 Entities, entity types, & bundles 
 Fields (formerly CCK) 
 The Entity API contrib module 
 How (and why) to define a custom entity 
 Using EntityFieldQuery 
 Defining entity property info 
 Leveraging the Entity Metadata Wrapper
Poll 
 Who here is... 
– Brand new to Drupal? 
– A site builder? 
– A module developer? 
– On the business side of things? 
 Who here has... 
– Created a custom D7 entity? 
– Not created a custom D7 entity?
D6 Data 
 (Custom database table) 
 User 
 Comment 
 File 
 Taxonomy vocabulary 
 Taxonomy term 
 Node 
– Page, Blog post, (custom content type)
D7 Data 
 (Custom database table) 
 Entity 
– User 
– Comment 
– File 
– Taxonomy vocabulary 
– Taxonomy term 
– Node 
• Page, Blog post, (custom content type) 
 (Custom entity type)
Entity Types 
 Elemental building block for most important data in 
Drupal 7 
 Represents a concept or noun 
 Different types store different data 
– Generally in a single DB table 
– Eg: Node 
• Title, body, created timestamp, etc. 
– Eg: User 
• Username, created timestamp, last visit timestamp, etc. 
 Defined using hook_entity_info()
Entity 
 Instance of an entity type 
 Examples of entities from core: 
– The user jdleonard with uid 80902 
– The page “Drupal Rocks” with nid 44 
 Any entity can be loaded with entity_load() 
– Eg: entity_load(‘node’, array(44, 65)) 
• Returns an array with two nodes with nids 44 and 65 
– Core provides some convenience wrappers 
• Eg: node_load() and user_load()
Entity Bundles 
 Subtype of an entity 
 Eg: Page and Blog post 
– Two content types (bundles) of node entity type 
 Not all entity types have more than one bundle 
– Eg: User 
• No subtypes; concept stands on its own
Why We Need Entity Bundles 
 Each entity type stores some data in a table 
– We call these pieces of data “properties” 
– Eg: node 
• Title, body, author (uid), created timestamp 
• But not all nodes are created equal 
– Page may have data beyond that captured by node 
– Blog posts get tagged 
– We need fields!
CCK: Content Construction Kit (D6) 
 Contrib module 
 Store additional data per content (node) content type 
 Eg: Fivestar 
– Contrib module leveraging contrib CCK API 
– Allows nodes to be rated (think 1-5 stars) 
– Eg: let users rate pages or blog posts
Fields (D7) 
 Core concept 
 Store additional data per entity type 
 Applies power of CCK to all entity types 
– Not just nodes! 
 Eg: Fivestar 
– Contrib module leveraging core Field API 
– Allows entities to be rated 
– Eg: let users rate pages, blog posts, users, comments, 
custom entities
Entities in Core vs Contrib 
 Entities are a Drupal 7 core concept 
 Core provides the “Entity API” 
– Functions and hooks to define and interact with 
entities, entity types, and entity bundles 
 Everything we've discussed so far is part of Drupal 7 
core (no contrib modules necessary) 
 Not everything “made it into” D7 core 
– Thankfully there's the “Entity API” contrib module 
• (confusingly named)
Entity API Contrib Module 
 Makes dealing with entities easier 
 Provides full CRUD functionality 
– CReate, Update, and Delete 
 Allows definition of metadata about entities 
 Optionally makes entity data 
– Exportable (for configuration) 
– Revisionable (eg: node revisions) 
 Optional administrative UI for managing entities 
 Object-oriented representation of entity types
Core or contrib Entity API? 
 Documentation for core's Entity API is separate 
from that for the Entity API contrib module 
 In practice, you'll probably always use the Entity 
API contrib module 
– It provides so much awesome functionality! 
 Don't get confused 
– Always install the Entity API contrib module when 
defining an entity 
– Make sure to read the contrib module's 
documentation
Contrib Modules Defining Entities 
 Commerce 
– Commerce Product, Commerce Payment Transaction 
 Organic Groups 
– OG Membership, OG Membership Type 
 Rules 
– Rules Configuration 
 Message (think activity stream) 
– Message, Message Type, Message Type Category 
 … and many more!
Example Custom Entity Type 
 TextbookMadness.com 
– Classified listings for textbooks at schools 
– Online price comparison shopping (prices from 
Amazon, Textbooks.com, etc.) 
 Online prices are 
– Fetched from a third-party API and stored by Drupal 
– Hereafter known as Offers
How Shall we Define an Offer? 
 We could use the UI to define an offer node with a 
bunch of fields to store pricing information 
 But there's a lot of overhead! 
– Don't need/want a page (path) per offer 
– Don't need/want revisions 
– Don't need/want node base table information 
• Language (and translation info), Title, Author, 
Published status, Created date, Commenting, 
Promoting, etc. 
– Don't need/want UI for adding, editing, etc. 
 We want an entity!
Implement hook_schema() 
$schema['tbm_offer'] = array( // SIMPLIFIED FOR SLIDE 
'fields' => array( 
'offer_id' => array('type' => 'serial'), 
'isbn' => array('type' => 'int'), 
'retailer_id' => array('type' => 'int'), 
'price' => array('type' => 'int'), 
'last_updated' => array('type' => 'int'), 
), 
'primary key' => array('offer_id') 
);
Implement hook_entity_info() 
$entities['tbm_offer'] = array( 
'label' => t('Offer'), 
'plural label' => t('Offers'), 
'entity class' => 'Entity', 
'controller class' => 'EntityAPIController', 
'module' => 'tbm', 
'base table' => 'tbm_offer', 
'fieldable' => FALSE, 
'entity keys' => array( 
'id' => 'offer_id', 
));
Make an Entity Type Exportable 
$entities['tbm_offer'] = array( 
'label' => t('Offer'), 
'plural label' => t('Offers'), 
'entity class' => 'Entity', 
'controller class' => 'EntityAPIControllerExportable', 
'module' => 'tbm', 
'base table' => 'tbm_offer', 
'fieldable' => FALSE, 'exportable' => TRUE, 
'entity keys' => array( 
'id' => 'offer_id', 'name' => 'my_machine_name' 
));
Make an Entity Type Revisionable 
$entities['tbm_offer'] = array( 
'label' => t('Offer'), 
'plural label' => t('Offers'), 
'entity class' => 'Entity', 
'controller class' => 'EntityAPIController', 
'module' => 'tbm', 
'base table' => 'tbm_offer', 'revision_table' => 'tbm_o_revision', 
'fieldable' => FALSE, 
'entity keys' => array( 
'id' => 'offer_id', 'revision' => 'revision_id', 
));
Other hook_entity_info() configuration 
$entities['tbm_offer'] = array( … 
'entity class' => 'TbmOfferEntity', // Extends Entity class 
'controller class' => 'TbmOfferEntityController', 
'access callback' => 'tbm_offer_access', 
'admin ui' => array( 
'path' => 'admin/structure/offers', 
'file' => 'tbm.admin.inc', 
), 
'label callback' => 'entity_class_label', 
'uri callback' => 'entity_class_uri', 
); // TbmOfferEntity->defaultLabel(), defaultUri()
Entity Property Info 
 hook_entity_property_info() 
– Defines entity metadata 
– Provided for core entities 
 Enables all kinds of great functionality in modules 
that leverage the Entity API contrib module 
– Examples coming later
Entity Property Info 
 Automatically generated from hook_schema() 
– Doesn't understand foreign key relationships 
(references) 
– Doesn't know when an integer is actually a date (eg: 
unix timestamps) 
 We can fill in the gaps with 
hook_entity_property_info_alter()

More Related Content

What's hot

Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in Drupal
Fredric Mitchell
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
drubb
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPGiorgio Sironi
 
Drupal as a Programmer-Friendly CMS at ConFoo
Drupal as a Programmer-Friendly CMS at ConFooDrupal as a Programmer-Friendly CMS at ConFoo
Drupal as a Programmer-Friendly CMS at ConFoo
Suzanne Dergacheva
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
Peter Friese
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
均民 戴
 
ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity apiDrupalCamp Kyiv Рысь
 
Configuration Entities in Drupal 8
Configuration Entities in Drupal 8Configuration Entities in Drupal 8
Configuration Entities in Drupal 8
Eugene Kulishov
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
Er. Gaurav Kumar
 
Custom content types & custom taxonomies in wordpress
Custom content types & custom taxonomies in wordpressCustom content types & custom taxonomies in wordpress
Custom content types & custom taxonomies in wordpress
stimasoft
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post TypesK.Adam White
 
Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
Marco Vito Moscaritolo
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
Ivano Malavolta
 

What's hot (16)

Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in Drupal
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHP
 
Drupal as a Programmer-Friendly CMS at ConFoo
Drupal as a Programmer-Friendly CMS at ConFooDrupal as a Programmer-Friendly CMS at ConFoo
Drupal as a Programmer-Friendly CMS at ConFoo
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity api
 
Configuration Entities in Drupal 8
Configuration Entities in Drupal 8Configuration Entities in Drupal 8
Configuration Entities in Drupal 8
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
 
Custom content types & custom taxonomies in wordpress
Custom content types & custom taxonomies in wordpressCustom content types & custom taxonomies in wordpress
Custom content types & custom taxonomies in wordpress
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
 
Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
 
Jpa
JpaJpa
Jpa
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
 

Viewers also liked

DrupalCafe Kyiv EntityAPI
DrupalCafe Kyiv EntityAPIDrupalCafe Kyiv EntityAPI
DrupalCafe Kyiv EntityAPIYuriy Gerasimov
 
From CCK to Entities in Drupal: New Power Tools
From CCK to Entities in Drupal: New Power ToolsFrom CCK to Entities in Drupal: New Power Tools
From CCK to Entities in Drupal: New Power Tools
Ryan Price
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
Eugenio Minardi
 
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
Italo Mairo
 
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
Cogapp
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
Ignacio Sánchez Holgueras
 

Viewers also liked (7)

DrupalCafe Kyiv EntityAPI
DrupalCafe Kyiv EntityAPIDrupalCafe Kyiv EntityAPI
DrupalCafe Kyiv EntityAPI
 
From CCK to Entities in Drupal: New Power Tools
From CCK to Entities in Drupal: New Power ToolsFrom CCK to Entities in Drupal: New Power Tools
From CCK to Entities in Drupal: New Power Tools
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
 
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
Pres why entity_forms_italo_mairo_drupal_days_milano_8_may_2014
 
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
Rich storytelling with Drupal, Paragraphs and Islandora DAMS (DrupalCamp Brig...
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 

Similar to Synapse india reviews on drupal 7 entities (stanford)

Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!tedbow
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
aminmesbahi
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!
Phase2
 
CMS content
CMS contentCMS content
CMS content
iemail808
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
DrupalDay
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting Started
MongoDB
 
Odoo (open erp) creating a module
Odoo (open erp) creating a moduleOdoo (open erp) creating a module
Odoo (open erp) creating a moduleTarun Behal
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Ranel Padon
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrine
isaaczfoster
 
Odoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a moduleOdoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a module
Tarun Behal
 
one|content : joomla on steroids
one|content : joomla on steroidsone|content : joomla on steroids
one|content : joomla on steroids
Paul Delbar
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptx
FarooqTariq8
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfoliocummings49
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1Asad Khan
 

Similar to Synapse india reviews on drupal 7 entities (stanford) (20)

Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!
 
CMS content
CMS contentCMS content
CMS content
 
Drupal 8: Fields reborn
Drupal 8: Fields rebornDrupal 8: Fields reborn
Drupal 8: Fields reborn
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting Started
 
Odoo (open erp) creating a module
Odoo (open erp) creating a moduleOdoo (open erp) creating a module
Odoo (open erp) creating a module
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrine
 
Odoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a moduleOdoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a module
 
one|content : joomla on steroids
one|content : joomla on steroidsone|content : joomla on steroids
one|content : joomla on steroids
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptx
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
.Net template solution architecture
.Net template solution architecture.Net template solution architecture
.Net template solution architecture
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Drupal 8 Hooks
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1
 

More from Tarunsingh198

Synapseindia android app programming
Synapseindia android app programmingSynapseindia android app programming
Synapseindia android app programming
Tarunsingh198
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello world
Tarunsingh198
 
Synapse india reviews on mobile devices
Synapse india reviews on mobile devicesSynapse india reviews on mobile devices
Synapse india reviews on mobile devices
Tarunsingh198
 
Synapse india reviews on drupal development
Synapse india reviews on drupal developmentSynapse india reviews on drupal development
Synapse india reviews on drupal development
Tarunsingh198
 
Synapse india reviews on drupal intro
Synapse india reviews on drupal introSynapse india reviews on drupal intro
Synapse india reviews on drupal intro
Tarunsingh198
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 

More from Tarunsingh198 (7)

Synapseindia android app programming
Synapseindia android app programmingSynapseindia android app programming
Synapseindia android app programming
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello world
 
Synapse india reviews on mobile devices
Synapse india reviews on mobile devicesSynapse india reviews on mobile devices
Synapse india reviews on mobile devices
 
Synapse india reviews on drupal development
Synapse india reviews on drupal developmentSynapse india reviews on drupal development
Synapse india reviews on drupal development
 
Synapse india reviews on drupal intro
Synapse india reviews on drupal introSynapse india reviews on drupal intro
Synapse india reviews on drupal intro
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 

Synapse india reviews on drupal 7 entities (stanford)

  • 1. Synapse India Reviews on Entities in Drupal 7 & the Entity API
  • 2. About Me  Founder & Chief Solutions Architect @ Modern Biz Consulting in Oakland  Strong development background  Working with Drupal since 2006  Developer, architect, project manager  Focus on complex web application development
  • 3. Agenda  Ways we represent data in D6 vs D7  Entities, entity types, & bundles  Fields (formerly CCK)  The Entity API contrib module  How (and why) to define a custom entity  Using EntityFieldQuery  Defining entity property info  Leveraging the Entity Metadata Wrapper
  • 4. Poll  Who here is... – Brand new to Drupal? – A site builder? – A module developer? – On the business side of things?  Who here has... – Created a custom D7 entity? – Not created a custom D7 entity?
  • 5. D6 Data  (Custom database table)  User  Comment  File  Taxonomy vocabulary  Taxonomy term  Node – Page, Blog post, (custom content type)
  • 6. D7 Data  (Custom database table)  Entity – User – Comment – File – Taxonomy vocabulary – Taxonomy term – Node • Page, Blog post, (custom content type)  (Custom entity type)
  • 7. Entity Types  Elemental building block for most important data in Drupal 7  Represents a concept or noun  Different types store different data – Generally in a single DB table – Eg: Node • Title, body, created timestamp, etc. – Eg: User • Username, created timestamp, last visit timestamp, etc.  Defined using hook_entity_info()
  • 8. Entity  Instance of an entity type  Examples of entities from core: – The user jdleonard with uid 80902 – The page “Drupal Rocks” with nid 44  Any entity can be loaded with entity_load() – Eg: entity_load(‘node’, array(44, 65)) • Returns an array with two nodes with nids 44 and 65 – Core provides some convenience wrappers • Eg: node_load() and user_load()
  • 9. Entity Bundles  Subtype of an entity  Eg: Page and Blog post – Two content types (bundles) of node entity type  Not all entity types have more than one bundle – Eg: User • No subtypes; concept stands on its own
  • 10. Why We Need Entity Bundles  Each entity type stores some data in a table – We call these pieces of data “properties” – Eg: node • Title, body, author (uid), created timestamp • But not all nodes are created equal – Page may have data beyond that captured by node – Blog posts get tagged – We need fields!
  • 11. CCK: Content Construction Kit (D6)  Contrib module  Store additional data per content (node) content type  Eg: Fivestar – Contrib module leveraging contrib CCK API – Allows nodes to be rated (think 1-5 stars) – Eg: let users rate pages or blog posts
  • 12. Fields (D7)  Core concept  Store additional data per entity type  Applies power of CCK to all entity types – Not just nodes!  Eg: Fivestar – Contrib module leveraging core Field API – Allows entities to be rated – Eg: let users rate pages, blog posts, users, comments, custom entities
  • 13. Entities in Core vs Contrib  Entities are a Drupal 7 core concept  Core provides the “Entity API” – Functions and hooks to define and interact with entities, entity types, and entity bundles  Everything we've discussed so far is part of Drupal 7 core (no contrib modules necessary)  Not everything “made it into” D7 core – Thankfully there's the “Entity API” contrib module • (confusingly named)
  • 14. Entity API Contrib Module  Makes dealing with entities easier  Provides full CRUD functionality – CReate, Update, and Delete  Allows definition of metadata about entities  Optionally makes entity data – Exportable (for configuration) – Revisionable (eg: node revisions)  Optional administrative UI for managing entities  Object-oriented representation of entity types
  • 15. Core or contrib Entity API?  Documentation for core's Entity API is separate from that for the Entity API contrib module  In practice, you'll probably always use the Entity API contrib module – It provides so much awesome functionality!  Don't get confused – Always install the Entity API contrib module when defining an entity – Make sure to read the contrib module's documentation
  • 16. Contrib Modules Defining Entities  Commerce – Commerce Product, Commerce Payment Transaction  Organic Groups – OG Membership, OG Membership Type  Rules – Rules Configuration  Message (think activity stream) – Message, Message Type, Message Type Category  … and many more!
  • 17. Example Custom Entity Type  TextbookMadness.com – Classified listings for textbooks at schools – Online price comparison shopping (prices from Amazon, Textbooks.com, etc.)  Online prices are – Fetched from a third-party API and stored by Drupal – Hereafter known as Offers
  • 18. How Shall we Define an Offer?  We could use the UI to define an offer node with a bunch of fields to store pricing information  But there's a lot of overhead! – Don't need/want a page (path) per offer – Don't need/want revisions – Don't need/want node base table information • Language (and translation info), Title, Author, Published status, Created date, Commenting, Promoting, etc. – Don't need/want UI for adding, editing, etc.  We want an entity!
  • 19. Implement hook_schema() $schema['tbm_offer'] = array( // SIMPLIFIED FOR SLIDE 'fields' => array( 'offer_id' => array('type' => 'serial'), 'isbn' => array('type' => 'int'), 'retailer_id' => array('type' => 'int'), 'price' => array('type' => 'int'), 'last_updated' => array('type' => 'int'), ), 'primary key' => array('offer_id') );
  • 20. Implement hook_entity_info() $entities['tbm_offer'] = array( 'label' => t('Offer'), 'plural label' => t('Offers'), 'entity class' => 'Entity', 'controller class' => 'EntityAPIController', 'module' => 'tbm', 'base table' => 'tbm_offer', 'fieldable' => FALSE, 'entity keys' => array( 'id' => 'offer_id', ));
  • 21. Make an Entity Type Exportable $entities['tbm_offer'] = array( 'label' => t('Offer'), 'plural label' => t('Offers'), 'entity class' => 'Entity', 'controller class' => 'EntityAPIControllerExportable', 'module' => 'tbm', 'base table' => 'tbm_offer', 'fieldable' => FALSE, 'exportable' => TRUE, 'entity keys' => array( 'id' => 'offer_id', 'name' => 'my_machine_name' ));
  • 22. Make an Entity Type Revisionable $entities['tbm_offer'] = array( 'label' => t('Offer'), 'plural label' => t('Offers'), 'entity class' => 'Entity', 'controller class' => 'EntityAPIController', 'module' => 'tbm', 'base table' => 'tbm_offer', 'revision_table' => 'tbm_o_revision', 'fieldable' => FALSE, 'entity keys' => array( 'id' => 'offer_id', 'revision' => 'revision_id', ));
  • 23. Other hook_entity_info() configuration $entities['tbm_offer'] = array( … 'entity class' => 'TbmOfferEntity', // Extends Entity class 'controller class' => 'TbmOfferEntityController', 'access callback' => 'tbm_offer_access', 'admin ui' => array( 'path' => 'admin/structure/offers', 'file' => 'tbm.admin.inc', ), 'label callback' => 'entity_class_label', 'uri callback' => 'entity_class_uri', ); // TbmOfferEntity->defaultLabel(), defaultUri()
  • 24. Entity Property Info  hook_entity_property_info() – Defines entity metadata – Provided for core entities  Enables all kinds of great functionality in modules that leverage the Entity API contrib module – Examples coming later
  • 25. Entity Property Info  Automatically generated from hook_schema() – Doesn't understand foreign key relationships (references) – Doesn't know when an integer is actually a date (eg: unix timestamps)  We can fill in the gaps with hook_entity_property_info_alter()