SLIDE 1 D r u p a l i z e Y
r D a t a : U s e E n t i t i e s !
Drupal Dev Days Barcelona 2012 by Wolfgang Ziegler // fago
SLIDE 2 Wo l f g a n g Z i e g l e r / / f a g
- from Vienna, Austria
- studied at the TU Vienna
- Drupal since 2005.
wolfgangziegler.net twitter.com/the_real_fago gplus.to/fago
SLIDE 3 O u t l i n e
- Introduction
- Interact with entities
- Providing a new entity type
- Expose non-DB entities
- Outlook
SLIDE 4
D r u p a l 7 : F i e l d s e v e r y wh e r e !
SLIDE 5
B u n d l e s
Entity type ↔ Node Bundle ↔ Node type Entity type ↔ Taxonomy term Bundle ↔ Vocabulary Entity type ↔ User Bundle ↔ {}
SLIDE 6 Wh i c h e n t i t i e s a r e t h e r e ?
- Core
- Modules:
- Drupal commerce
- Organic groups
- Profile2
- Heartbeat and Message
- File entity
SLIDE 7 N
e mo d u l e s E n t i t y mo d u l e s
SLIDE 8 E n t i t y A P I
a t f
?
Unified way to access data.
SLIDE 9 User Node Comment Profile Product Search Vote Groups Entity reference Rules Entity
SLIDE 10
I n t e r a c t i n g wi t h e n t i t i e s
SLIDE 11 E n t i t y A P I mo d u l e
Assists you with
- interacting with entities
- and providing new entity types
SLIDE 12 E n t i t y A P I F u n c t i
s
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()
SLIDE 13
Me t a d a t a Wr a p p e r
$wrapper = entity_metadata_wrapper('node', $nid); $mail = $wrapper->author->mail->value(); $wrapper->author->mail->set('fago@example.com'); $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');
SLIDE 14 E n t i t y p r
e r t y i n f
- $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', );
SLIDE 15 P r
e r t y i n f
- ?
- Unified access to entity data
- Validation
- Access information
SLIDE 16 H
mo d u l e s u s e i t
- Drupal Commerce, VBO, OG
- Rules, Search API
- RestWS, WSClient
- Microdata, RDFx
- Entity tokens
- Entity Views (Search API, EFQ views)
SLIDE 17 P r
i d i n g a n e n t i t y t y p e
- Implement hook_entity_info()
- Specify your 'controller class'
- Implement hook_schema()
SLIDE 18
E n t i t y A P I mo d u l e
$profile = entity_create('profile2', array( 'type' => 'main', 'user'=> $account, )); $profile->save(); $profile->delete(); entity_delete_multiple('profile2', array(1, 2, 3));
SLIDE 19 I n t e g r a t i n g y
r e n t i t y t y p e
Tokens Views Rules Property Info Field API Schema CRUD controller Info XY
SLIDE 20 E x p
t a b l e e n t i t i e s
similar to CTools exportables, but...
- unified CRUD interface
- regular CRUD hooks
- synced to the DB
- Admin UI, Features, i18n, Views,
Tokens,...
SLIDE 21 I n t e g r a t i n g y
r e x p
t a b l e e n t i t y
Schema CRUD controller Info Tokens Property Info Views i18n Features Admin UI
SLIDE 22
SLIDE 23 E x a mp l e : P r
i l e 2
Profile2:
Profile2 types:
- Entity type
- Bundle of Profile2
- Exportable
SLIDE 24 P r
i l e 2 t
n a p a r t
- CRUD, Field API
- Permissions, Access
- Profile form, display
- Admin UI, I18n
- Views, CTools, Rules, Tokens,
Features, Search API
Y
r j
SLIDE 25 h
wo r k d
e , l e t ' s e n j
i t .
SLIDE 26
- NoSQL, Doctrine, PHPCR
- Remote entities
- Data integration
SLIDE 27 N
B e n t i t i e s + F i e l d s ?
SLIDE 28 N
B e n t i t i e s
CRUD controller Info Property Info Schema Controller Info Tokens Rules Views XY
SLIDE 29 Wh a t d
s i t b u y u s ?
- Classed CRUD API
- CRUD Hooks
- Tokens
- Entity reference
- Rules, Rules Links
- Search API, Views integration, RestWS
- …
SLIDE 30 D r u p a l i z e y
r d a t a !
SLIDE 31
E x a mp l e . . .
SLIDE 32 G
l e P i c a s a e n t i t i e s
http://drupal.org/sandbox/fago/1493180
SLIDE 33
SLIDE 34
SLIDE 35 R
f
i mp r
e me n t s
- Generate display
- Generate form
- Ready-only mode
SLIDE 36
D r u p a l 8
SLIDE 37 C l a s s e d
j e c t s . . . !
$comment = entity_create('comment', array( 'nid' => $node->nid, )); $comment->save(); echo $comment->id(); $comment->delete(); entity_delete_multiple('comment', array(1, 2, 3));
SLIDE 38 C
n t s i n D r u p a l 8
class CommentStorageController extends EntityDatabaseStorageController { … } class Comment extends Entity { … } class Entity implements EntityInterface { … }
SLIDE 39 E n t i t y P r
e r t y A P I
- Similar to the entity metadata wrappers,
but improved and built-in!
- Unified API for properties and fields
- Property definitions / metadata
- D8MI, WSCCI, Content staging, ...
- Improved DX!
SLIDE 40 WS C C I We b S e r v i c e s F
ma t R e p
t
http://groups.drupal.org/node/237443