drupalize your data use entities
DESCRIPTION
Drupalize your data use entities Druapl 7TRANSCRIPT
![Page 1: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/1.jpg)
![Page 2: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/2.jpg)
Coding and development
Drupalize Your Data: Use Entities!
Presented by Wolfgang Ziegler // fago
![Page 3: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/3.jpg)
Wolfgang Ziegler // fago
• from Vienna, Austria
• studied at the TU Vienna
• Drupal since 2005.
wolfgangziegler.nettwitter.com/the_real_fagogplus.to/fago
![Page 4: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/4.jpg)
Outline
• Introduction
• Interact with entities
• Providing a new entity type
• Expose non-DB entities
• Outlook
![Page 5: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/5.jpg)
Drupal 7: Fields everywhere!
![Page 6: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/6.jpg)
Bundles
Entity type ↔ NodeBundle ↔ Node type
Entity type ↔ Taxonomy termBundle ↔ Vocabulary
Entity type ↔ UserBundle ↔ {}
![Page 7: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/7.jpg)
Which entities are there?
• Core
• Modules:
• Drupal commerce
• Organic groups
• Profile2
• Heartbeat and Message
• File entity
![Page 8: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/8.jpg)
Node modules
Entity modules
![Page 9: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/9.jpg)
Entity API - What for?
Unified way to access data.
![Page 10: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/10.jpg)
User
Node
Comment
Profile
Product
Search
Vote
Groups
Entityreference
Rules
Entity
![Page 11: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/11.jpg)
Interacting with entities
![Page 12: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/12.jpg)
Entity API module
Assists you with
• interacting with entities
• and providing new entity types
![Page 13: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/13.jpg)
Entity API Functions
Drupal Core
Entity API module
entity_save()entity_load()
entity_get_info()
entity_metadata_wrapper()
entity_view()
entity_access()
entity_create()
entity_id()
entity_get_property_info()
entity_delete()
![Page 14: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/14.jpg)
Metadata Wrapper
$wrapper = entity_metadata_wrapper('node', $nid);
$mail = $wrapper>author>mail>value();
$wrapper>author>mail>set('[email protected]');
$text = $wrapper>field_text>value();
$wrapper>language('de')>field_text>value();
$terms = $wrapper>field_tags>value();
$wrapper>field_tags[] = $term;
$options = $wrapper>field_tags>optionsList();
$label = $wrapper>field_tags[0]>label();
$access = $wrapper>field_tags>access('edit');
![Page 15: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/15.jpg)
Metadata Wrapper
$wrapper = entity_metadata_wrapper('node', $nid);
$mail = $wrapper>author>mail>value();
$wrapper>author>mail>set('[email protected]');
$text = $wrapper>field_text>value();
$wrapper>language('de')>field_text>value();
$terms = $wrapper>field_tags>value();
$wrapper>field_tags[] = $term;
$options = $wrapper>field_tags>optionsList();
$label = $wrapper>field_tags[0]>label();
$access = $wrapper>field_tags>access('edit');
![Page 16: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/16.jpg)
Entity property info
$properties['mail'] = array(
'label' => t("Email"),
'type' => 'text',
'description' => t("The email address of ..."),
'setter callback' => 'entity_property_verbatim_set',
'validation callback' => 'valid_email_address',
'required' => TRUE,
'access callback' => 'user_properties_access',
'schema field' => 'mail',
);
![Page 17: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/17.jpg)
Property info?
• Unified access to entity data
• Validation
• Access information
![Page 18: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/18.jpg)
How modules use it
• Drupal Commerce, VBO, OG
• Rules, Search API
• Microdata
• RestWS, WSClient
• Entity tokens
• Entity Views
![Page 19: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/19.jpg)
Providing an entity type
• Implement hook_entity_info()
• Specify your 'controller class'
• Implement hook_schema()
![Page 20: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/20.jpg)
Entity API module
$profile = entity_create('profile2', array(
'type' => 'main',
'user'=> $account,
));
$profile>save();
$profile>delete();
entity_delete_multiple('profile2', array(1, 2, 3));
![Page 21: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/21.jpg)
Integrating your entity type
TokensViews Rules
PropertyInfo
Field API
SchemaCRUD
controllerInfo
XY
![Page 22: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/22.jpg)
Exportable entities
similar to CTools exportables, but...
• unified CRUD interface
• synced to the DB
• regular CRUD hooks
• Views, Tokens, Features, i18n, ...
![Page 23: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/23.jpg)
Integrating your exportable entity
SchemaCRUD
controllerInfo
Tokens
PropertyInfo
Views i18nFeaturesAdmin
UI
![Page 24: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/24.jpg)
Apocalypse now?
• Provide an entity
• get a bullshit of not fitting stuff
•
• Find a good metafa, or cite for it.
• is it an elephant or moskito?
![Page 25: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/25.jpg)
Module developers: Think
• what makes it applicable?
• label, URI?
• field?
• custom on,off
• example: no display,no page → no metadata tags
![Page 26: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/26.jpg)
![Page 27: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/27.jpg)
Example: Profile2
Profile2:
• Entity type
Profile2 types:
• Entity type
• Bundle of Profile2
• Exportable
![Page 28: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/28.jpg)
Profile2 torn apart
• CRUD, Field API
• Permissions, Access
• Profile form, display
• Admin UI, I18n
• Views, CTools, Rules, Tokens, Features, Search API
Your job
![Page 29: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/29.jpg)
homework done,let's enjoy it.
![Page 30: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/30.jpg)
• NoSQL, Doctrine, PHPCR
• Remote entities
• Data integration
![Page 31: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/31.jpg)
Non-DB entities+
Fields?
![Page 32: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/32.jpg)
Non-DB entities
Field storage
Info
PropertyInfo
Field API
SchemaControllerInfo TokensRulesViews XY
CRUDcontroller
![Page 33: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/33.jpg)
Non-DB entities
CRUDcontroller
InfoProperty
Info
SchemaControllerInfo TokensRulesViews XY
![Page 34: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/34.jpg)
What does it buy us?
• Classed CRUD API
• CRUD Hooks
• Tokens
• Entity reference
• Rules, Rules Links
• Search API, Views integration, RestWS
• …
![Page 35: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/35.jpg)
Drupalize your data!
![Page 36: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/36.jpg)
howto slide?
![Page 37: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/37.jpg)
Example...
![Page 38: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/38.jpg)
Google Picasa entities
http://drupal.org/sandbox/fago/1493180
![Page 39: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/39.jpg)
![Page 40: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/40.jpg)
![Page 41: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/41.jpg)
Room for improvements
• EFQ Views
• Ready-only mode
• Generated display
• Generated form
![Page 42: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/42.jpg)
Drupal 8
![Page 43: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/43.jpg)
Comments in Drupal 8
$comment = entity_create('comment', array(
'nid' => $node>nid,
));
$comment>save();
echo $comment>id();
$comment>delete();
entity_delete_multiple('comment', array(1, 2, 3));
![Page 44: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/44.jpg)
Comments in Drupal 8
class CommentStorageController extends
EntityDatabaseStorageController {
…
}
class Comment extends Entity {
…
}
class Entity implements EntityInterface {
…
}
![Page 45: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/45.jpg)
Questions?
![Page 46: Drupalize your data use entities](https://reader033.vdocuments.site/reader033/viewer/2022060117/5584c44dd8b42aeb138b469a/html5/thumbnails/46.jpg)
What did you think?
Locate this session on theDrupalCon Denver website
http://denver2012.drupal.org/program
Click the “Take the Survey” link.
Thank You!