Simplified Entity API

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
philippze's picture

Hallo!

I'm relatively new to Drupal and wonder how tedious it is to manage complex data structures using entities. Even when using the Entity API module I still have the feeling that I explicitely type a lot of things which could be done automatically. I found that even with 150 lines of code the usage of entities can be simplified a lot.

I'm thinking of contributing a module which contains an abstract base class for Entities that provides features like
- saving and reading entities
- creating the sql tables
- providing a form for adding and changing entities
- displaying the entity in any desired format
The module should support many-to-many relationships (which is important for my purposes).

When I represent a musical instrument using the poor version of the module I already realized, it looks like this:

class simple_entity_example_Instrument extends simple_entity_Entity {
    static public $database = 'simple_entity_instrument';
    static public $id_field = 'iid';
static public $fields = array('iid', 'name', 'plural_name');
static public $form = array(
       'name' => array(
          '#type' => 'textfield',
         '#title' => "The instrument's name",
           '#required' => TRUE,
          '#default_value' => '',
     ),
     'plural_name' => array(
           '#type' => 'textfield',
         '#title' => "The instrument's name in plural",
         '#required' => FALSE,
         '#default_value' => '',
     )
  );
static public $unique_identifier = array('name');
}

Except from these lines there should not be much left to do. For example, to obtain an array of all Instrument entities in a certain format, I type
simple_entity_example_Instrument::all_values('%name% (%plural_name%)');

and get the output
array( 'Violin (Violins)', ...

My current bad and poor version is far away from perfection, and I would need the help of an experienced drupal expert to improve it (and to make it consistent with it with the existing Entity API module). However, it remarkably simplifies the management of complex data structures. I wonder why I could not find a similar module yet.

Thanks a lot for any comments
Philipp

Comments

ECK

fmizzell's picture

Why don't you use ECK (Entity Construction Kit)? The whole purpose of it is to abstract out those repetitious tasks that you are mentioning, and if it doesn't do what you want, I would be more than happy to guide you through the architecture of the module so you can improve it for your purpose.

gook ECK

philippze's picture

Hallo and thanks a lot! I was not aware of your module, but it is very much what I'm looking for. It only seems that the ECK has no possibility to have many-to-many relationships between entities, and I would like to add this feature. Where should we continue to discuss?

Relationships

fmizzell's picture

I think you are coming from the same kind of mindset that inspired ECK. I wanted to think of my sites as diagrams where objects interact with one another through relationships. ECK fills the data modeling void, but not the relations part of the equation. For relations between my data objects I use the 'relation' module. I do have a sandox project call "econnect" that attempts to integrate ECK and relation in useful ways, but it is very elementary at the moment. If you want to talk about the details of what you have in mind, I am usually in irc pretty regularly, and there is a group for ECK related discussions also if you want to continue discussing over there.

Contributed Module Ideas

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: