D r u p a l i z e Y o u r D a t a : U s e E n - - PowerPoint PPT Presentation

d r u p a l i z e y o u r d a t a u s e e n t i t i e s
SMART_READER_LITE
LIVE PREVIEW

D r u p a l i z e Y o u r D a t a : U s e E n - - PowerPoint PPT Presentation

D r u p a l i z e Y o u 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 Wo l f g a n g Z i e g l e r / / f a g o from Vienna, Austria studied


slide-1
SLIDE 1

D r u p a l i z e Y

  • u

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
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
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
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
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
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
SLIDE 7

N

  • d

e mo d u l e s E n t i t y mo d u l e s

slide-8
SLIDE 8

E n t i t y A P I

  • Wh

a t f

  • r

?

Unified way to access data.

slide-9
SLIDE 9

User Node Comment Profile Product Search Vote Groups Entity reference Rules Entity

slide-10
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
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
SLIDE 12

E n t i t y A P I F u n c t i

  • n

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
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
SLIDE 14

E n t i t y p r

  • p

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
SLIDE 15

P r

  • p

e r t y i n f

  • ?
  • Unified access to entity data
  • Validation
  • Access information
slide-16
SLIDE 16

H

  • w

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
SLIDE 17

P r

  • v

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
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
SLIDE 19

I n t e g r a t i n g y

  • u

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
SLIDE 20

E x p

  • r

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
SLIDE 21

I n t e g r a t i n g y

  • u

r e x p

  • r

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 22
slide-23
SLIDE 23

E x a mp l e : P r

  • f

i l e 2

Profile2:

  • Entity type

Profile2 types:

  • Entity type
  • Bundle of Profile2
  • Exportable
slide-24
SLIDE 24

P r

  • f

i l e 2 t

  • r

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

  • u

r j

  • b
slide-25
SLIDE 25

h

  • me

wo r k d

  • n

e , l e t ' s e n j

  • y

i t .

slide-26
SLIDE 26
  • NoSQL, Doctrine, PHPCR
  • Remote entities
  • Data integration
slide-27
SLIDE 27

N

  • n
  • D

B e n t i t i e s + F i e l d s ?

slide-28
SLIDE 28

N

  • n
  • D

B e n t i t i e s

CRUD controller Info Property Info Schema Controller Info Tokens Rules Views XY

slide-29
SLIDE 29

Wh a t d

  • e

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
SLIDE 30

D r u p a l i z e y

  • u

r d a t a !

slide-31
SLIDE 31

E x a mp l e . . .

slide-32
SLIDE 32

G

  • 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 33
slide-34
SLIDE 34
slide-35
SLIDE 35

R

  • m

f

  • r

i mp r

  • v

e me n t s

  • Generate display
  • Generate form
  • Ready-only mode
slide-36
SLIDE 36

D r u p a l 8

slide-37
SLIDE 37

C l a s s e d

  • b

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
SLIDE 38

C

  • mme

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
SLIDE 39

E n t i t y P r

  • p

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
SLIDE 40

WS C C I We b S e r v i c e s F

  • r

ma t R e p

  • r

t

http://groups.drupal.org/node/237443

slide-41
SLIDE 41

Q u e s t i

  • n

s ?

slide-42
SLIDE 42

T h a n k y

  • u

!