How to use Entity API to enhance your custom application

In this session we´ll discuss the many advantages of creating your own custom Drupal application using the Entity API. We´ll look into the different steps to create your own custom entity types and will try to exemplify them with our - soon to be published - Elearning module. 

Drupal development has slowly moved from a 'node' approach to an 'entity' approach. In D6 we used custom node types and the NodeAPI to make the funky stuff happen. While D7 still made this approach possible, it favoured the 'entity way' which was immensely enhanced by the contributed Entity API module. Many 'big' modules like Profile2 and Commerce used the Entity API, which later became part of core in D8.

Why Entity API? 

You could save any data you need in a table. Just declare the hook_schema and populate your table upon, for example, hook_node_insert. But how do you get Drupal to display your table values in views? How do you control access to your custom table? 

By declaring an entity type that matches the table you won´t be dealing directly with the table anymore, but with the entity. That means: full views integration, adding fields to anything we like, easy functions to controll the entity, easy referencing between enties, custom access control for each entity, and much more.

For our Elearning module we created several custom entity types, such as questions, exercises, course access, exercise results, question results and more. Every bit of custom data was saved as an entity. In some cases fieldable, in others allowing custom bundles to be created (for example question types).

What can you learn in this session?

  • How to create a custom entity.
  • What bundles, properties, fields and entity types are.
  • How to override standard entity API field definitions for views.
  • How to enable views relations between different entities using the entity API
  • Different specific use cases of the entity API in our Elearning module.
  • And more

Who is this session for?

If you´re a seasoned coder you´ll probably have learned all this already by looking at modules like Commerce, Profile2 or some of the existing example modules. But if all that code is just a bit daunting and the theory behind it a bit too abstract, this session might help you on the way to quickly understand what entity API is all about and how it might save you a good few hours of coding.

La presentación en formato PREZI:

Sandbox del módulo 'elearning' en desarrollo

DrupalCampSpain 2013