Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Better Entity Property Information

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:02
    [Working with Entities in Drupal 7, Chapter 15]
  • 0:04
    [with Joe Shindelar]
  • 0:06
    In this lesson, I want to take a look at hook_entity_property_info,
  • 0:09
    which is going to allow us to describe the properties on our entity in more detail
  • 0:14
    to the Entity API.
  • 0:17
    We've seen that you can do things like get some automated support for Views
  • 0:21
    using the Entity API.
  • 0:24
    But in order for it to fully understand all the properties on our entity,
  • 0:27
    we need to describe them.
  • 0:29
    We're going to tell the Entity API

Better Entity Property Information


In order to make the most of the entity APIs integration with other modules, such as Views, we need to describe the properties of our entity in more detail. The API can infer some information about a property based on our schema but we need to tell it that the integer stored in the updated_at column is actually a timestamp. We will do this by implementing hook_entity_property_info() and describing each of our entities properties. With these definitions in place you will be able to use the formatters in Views much like you would for individual fields on content types provided by core.

Note: Before you implement hook_entity_property_info() the API makes an educated guess about each property but once you've defined a single property, the API expects you to define all of the properties for your entity. Use the .install file in your module to get a complete list of the properties you need to define with hook_property_entity_info. You can also define additional properties that aren't mapped to fields in the database (these can be used for static properties).

Log in or sign up to download companion files.
Additional resources: