I'm a bit lost on how to create a custom entity. I need to go beyond the basics, but every example of Entity implementation I have seen has been different from one another and I am confused on the best way to go about this. I have read the docs included here, and in entity.inc, but wind up in circles.

I need to create an Entity that is like a node. It will store data, have a path, view modes, be used in Views, etc, and fieldable. Here is what I am using, gleamed from what I saw other modules doing:

Code:

$entities['isilink_property'] = array(
		'label' => t('ISILink Property'),
		'entity class' => 'ISILinkProperty',
		'controller class' => 'ISILinkPropertyController',
		'token type' => 'isilink_property',
		'base table' => 'isilink_property',
		'uri callback' => 'entity_class_uri',
		'fieldable' => TRUE,
		'view modes' => array(
			'full' => array(
				'label' => 'Full View',
				'custom settings' => FALSE,
			),
			'search' => array(
				'label' => 'Search View',
				'custom settings' => TRUE,
			),
			'list' => array(
				'label' => 'List View',
				'custom settings' => TRUE,
			),
		),
		'bundles' => array(
			'isilink_property' => array(
				'label' => t('ISILink Property'),
				'admin' => array(
					'path' => 'admin/structure/isilink/manage/isilink_property',
					'real path' => 'admin/structure/isilink/manage/isilink-property',
					'bundle argument' => 4,
				),
			),
		),
		'entity keys' => array(
			'id' => 'id',
		),
		'admin ui' => array(
			'path' => 'admin/content/isilink_property',
			'file' => 'includes/isilink.property.admin.inc',
			'controller class' => 'ISILinkPropertyUIController',
			'menu wildcard' => '%isilink_property',
		),
		'module' => 'isilink',
		'access callback' => 'isilink_property_entity_access',
  );

As you can see above, I am trying to get the following:

  1. Define an Entity
  2. Provide Field management
  3. Provide a management UI for existing property Entities (like admin/content/node)

The first thing I cannot figure out is when I define the above in hook_entity_info(), drush rr inserts the menu paths above then removes the, (registry rebuild). Rebuilding the menu brings them back (checking menu_router table I can see them appear and disappear). Is this intentional, or is the definition wrong?

Second, when I visit admin/structure, I get two tabs now on the top for Manage Fields and Manage Display, pertaining to my entity. Why are these showing up and how can I get them to not do that? In fact what is a good way to do that to keep everything consistent (admin/(mymodule)/(myentity)/(whatever path))?

Comments

Anonymous’s picture

I've found that this is a good tutorial to follow: http://www.trellon.com/content/blog/creating-own-entities-entity-api

kevinquillen’s picture

Thanks- I can't believe its been 4 months already! I've got a much better handle on this now than then. I'm definitely bookmarking that for coworkers.

Anonymous’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Rebekaloz’s picture

I can't make my entity fieldable, this is my code:
Eventhough I set the fieldable property to true and I have a single bundle defined.
I dont get the extra operations tabs.
Please the link that kevinquillen provided is broken.
Thank you!!


/**
 * Implements hook_entity_info().
 */
function slideentity_entity_info() {
        $return = array();
        $return['slide'] = array(
          'label' => t('Slide'),
          'base table' => 'slideentity_slide',
          
          'entity keys' => array(
            'id' => 'id',
            'label' => 'name',
          ),
          'uri callback' => 'entity_class_uri',
          // These are the default controllers.
          // 'entity class' => 'Entity',
          'entity class' => 'SlideEntity',
          // 'controller class' => 'DrupalDefaultEntityController',
          // Other options provided by the EntityAPI contrib module:
          // 'controller class' => 'EntityAPIController ',
          // 'controller class' => 'EntityAPIControllerExportable',
          'controller class' => 'SlideEntityController',
          // The information below is used to extend the EntityDefaultUIController
          'admin ui' => array(
            'path' => 'admin/slideentity',
            'controller class' => 'SlideEntityUIController',
            'menu wildcard' => '%slideentity',
            'file' => 'slideentity.admin.inc',
          ),
          'module' => 'slideentity',
          'fieldable' => TRUE,
          // Access callback to determine permisisons.
          'access callback' => 'slideentity_access_callback',
          // Tell FieldAPI that fields can be attached to our slide entity
          
          'bundles' => array(
              'slide' => array(
                'label' => t('Slide'),
                'admin' => array(
                  'path' => 'admin/slideentity',
                  'access arguments' => array('administer slide'),
                  'bundle argument' => 4,
                ),
              ),
            ),
          'views controller class' => 'EntityDefaultViewsController',
          
        );

        return $return;
      }