Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

entity_create

entity_delete

entity_save

entity_access

function exercise_entity_property_info_alter(&$info) {

$properties = array(

'uid' => array(

'type' => 'user',

'label' => t('Author'),

'description' => t('The author of this exercise'),

),

);

$info['exercise']['properties'] = array_replace_recursive($info['exercise']['properties'], $properties);

}

Wolfgang Ziegler // Fago

Why

How

When

What

Example

this presentation?

use the entity API?

to build your own entity

is an entity?

Elearning module

The e-learning module creates a framework for online teaching and learning.

vid

Open Question

Vocabulary

Vocabulary

Practice

name

machine_name

description

hierarchy

module

weight

Testing

4. Use your entity

3. Add the admin

4. Complete the property metadata

2. Declare the entity type

1. Create the table

Multiple choice

properties

Nid

tid

uid

  • Every entity type has its own table in the database.

Unique identifier

entity_metadata_wrapper

hook_entity_property_info_alter

Vocabulary (vid)

Content type/

node type/

type

Node

User

User

Taxonomy

term

  • Every entity belongs to an entity type and a bundle.

Bundle

  • Node
  • User
  • Taxonomy term
  • Anything

Entity type

Metadata of a property

dpm() in myentity_entity_property_info_alter

hook_schema

2. The form

  • Fields are defined per bundle.

Other properties

$referenced_id = $my_entity->field_entity_reference['und'][0]['target_id'];

$referenced_id = $my_entity->field_entity_reference[LANGUAGE_NONE][0]['target_id'];

$referenced_object = entity_load('referenced_entity_type', $referenced_id);

function my_entity_form($form, &$form_state, $entity){

$form['property_A'] = array(...);

$form['property_B'] = array(...);

field_attach_form(..);

return $form;

}

  • in yourmodule.install
  • return $schema['my_entity_type'] = array(...);
  • Use blob type for flexible properties.
  • Foreign keys are for documentation purposes only
  • property = form element
  • field_attach_form
  • hook_field_extra_fields

Name

Description

Format

Weight

  • label
  • description
  • type
  • text
  • token
  • integer
  • decimal
  • date
  • duration
  • boolean
  • uri
  • entity
  • struct
  • list
  • getter callback
  • setter callback
  • more ...

User name

Password

Mail

Theme

signature

signature_format

created

Why Entity API?

array_replace_recursive

$wrapper = entity_metadata_wrapper ('my_entity_type', $my_entity);

$referenced_object = $wrapper->field_entity_reference->value();

$mail_of_author = $wrapper->uid->mail->value();

$wrapper->uid->mail->set('nuezweb@exampe.com');

Why Entity?

entity

reference

setter callback required

entity

reference

array_replace_recursive

entity

reference

http://drupalcamp2013.nuezweb.com

https://drupal.org/sandbox/nuez/2054439

Put in order

Question

Course

Unit

Exercise

Question

Entity API (D7) extends de core Entity and adds:

course/%/unit/%

course/%

course/%/unit/%/exercise/%

course/%/unit/%/exercise/%/question/%

  • Can you do it with node?
  • Do you need a page? (node/%)?
  • Do you need comments?
  • Do you need 'promoted' or 'sticky'?
  • Do you want it 'clean'?

Elearning module

  • EntityAPIController
  • CRUD (create/read/update/delete)
  • entity_metadata_wrapper
  • rules controller class
  • views controller class
  • features controller class
  • i18n controller class
  • automatic fields administration
  • Do you want to control access to your entity?

Unit result

Exercise result

Question result

+ Feedback

Non Fieldable entities

Fieldable entities

Course Access

course/%course/access

  • Course access
  • Course result
  • Unit result
  • Exercise result
  • Question result
  • Course
  • Unit
  • Exercise
  • Question

User

http://prezi.com/h3ncpgzx7gur

Teun van Veggel

@nuezweb

Changed

Comment

Promote

Sticky

tnid

translate

Vid

Language

Title

Uid

Status

Created

hook_entity_info

  • In D7 the hook_entity_info is extended by the EntityAPI
  • defines
  • entity class (defaults to Entity)
  • entity controller class (defaults to EntityAPIController)
  • base table ('my_entity_type')
  • and more...

EntityAPIController

  • Defines CRUD methods
  • Create
  • Read
  • Update
  • Delete
  • And
  • load
  • view
  • export
  • import
  • etc..

MyCustomController

MyCustomController extends EntityAPIController{

public function load($ids = array(), $conditions = array()) {

$entities = parent::load($ids, $conditions);

// do stuff

return $entities;

}

}

1. hook_menu

entity_create('my_entity_type', array('type'=> $type);

  • Page for adding entity
  • Page for editing entity
  • Page for administering the entities

mymodule.views_defaults.inc

3. Submitting the form

  • entity_form_submit_build_entity

function my_entity_form_submit($form, &$form_state) {

$entity = $form_state['entity'];

entity_form_submit_build_entity('my_entity_type', $entity, $form, $form_state);

entity_save('my_entity_type- , $entity);

}

How to use

Entity API

to enhance your

custom application

Learn more about creating dynamic, engaging presentations with Prezi