Community Documentation

Property behaviors

Last updated October 13, 2012. Created by fmizzell on December 14, 2011.
Edited by Kristen Pol. Log in to edit this page.

Sometime in ECK 1.x, the ability to add/delete properties from an entity type was introduced. The slight problem was that there was no "good" way to add any sort of use or functionality to the properties. ECK by default managed 3 properties that you could create ('created', 'changed' and 'uid') but, other than that the rest of default and custom properties, were sort of useless.

Even back then, it was not terribly hard to add functionality to a property. It is easy to implement one of the many entity hooks provided by the Entity API (contributed entity module) and add some information to a property during a save or a load. The problem I saw with that approach was that this would not make our code very reusable. Yes, we can reuse it by defining the functionality in a function and then calling that function from multiple entity hooks, or by calling it from our own Entity class, but I thought that ECK could help make all of these easier.

That is why the "Property Behavior" system was developed. This system allows us to create one file with all of the functionality we want to provide for a property, and ECK will make this functionality available for any property on any entity type.

So, in ECK 7.x-2.x, all of that default functionality attached to 'created', 'changed', and 'uid' is exposed as behaviors so that they can easily be used by other properties, or replaced if more powerful and interesting functionality is needed.

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Intermediate
Keywords
entity

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.