Community Documentation

Working with Entity Types

Last updated February 8, 2013. Created by fmizzell on October 31, 2012.
Edited by komlenic. Log in to edit this page.

In our example, we are trying to create a site where we will have vehicle listings. For that purpose we needed an entity type to store our vehicle entities.

To create an entity type with eck we need to go to /admin/structure/entity-type

Then we will have the option to "add entity type" to drupal.

After clicking on "add entity type", we need to give our Entity type a name. For our example we will call our entity type "Vehicle". There is also an optional field to give a bundle name. When we were defining our data model we realized that we needed 2 bundles or subtypes: car and truck. By default, eck creates one bundle with every entity type, and this optional field gives us a chance to give that bundle a name instead of the default (By default the bundle will be name the same than the entity type). Since we know that we need a car and truck bundles, lets go ahead and type "Car" in the optional Bundle field.

In this screen we also have an option to add commonly used properties to our entity type. This default properties are managed by eck, so the created date gets recorded automatically when an entity of this type is created, the author property gets set to the active user in the system during the creation of an entity etc.

Default properties can be activated on this screen or at a later time from the screen where extra properties can be added.

For right now lets not use any of our default properties and click save.

After clicking save we will see a message letting us know that our entity type has been created. If we go back to /admin/structure/entity-type we will see that we now have our Vehicle entity type, so we can continue to add the necessary properties to store information in our vehicle entities.

Comments

How to add custom properties for filling by user via form?

I want to add my custom properties to entity (text, int), without creating separate field via field api, because I want to see all it in one sql table.
But if I add this properties, I must select Behavior (Created, Changed, Author, Title) - what must I select for add separate items into entity create form?
And can I add multiline (textarea) property?

you can create your own

you can create your own behaviors, that creates widgets, formatters and functionality to any property. The ones that come with eck are there just to give some functionality to the default properties, if you want anything happening with properties, you will have to create your own behaviors.

next for this documentation?

Unless it is somewhere else where I have not yet discovered it, it seems that the documentation now needs to describe how to allow a site user to easily create entities (such as different cars and truck as per your example), and then how to link this information to a content type.

Page status

About this page

Drupal version
Drupal 7.x
Audience
Site builders
Level
Intermediate

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.