I am trying to use the entity_form() function to output the edit form for an entity on my page. Seems simple...

The function returns FALSE which seems to be due to the entity info not having any result for "form callback".

After a few hours, the closest I can find is someone who seems to have hacked around it in his own sandbox module. http://drupalcode.org/sandbox/marmalade/1921824.git/blob/c3188bb232fb07c...

There must be a clean way to do this within the ECK module, but I'm afraid my head is swimming trying to understand the relationship between ECK and Entity API. Do they produce different kinds of entities? So confusing.

Comments

fmizzell’s picture

That is true, eck does not define a form callback in the info array, but that is something trivial to add. The form function is eck__entity__form. So a calling drupal_get_form("eck__entity__form", $entity); should do the trick. ECK also provides a couple of wrapper functions that actually create/or load the entity for you and returns the form, these are eck__entity__add, and eck__entity__edit. All this function are in eck.entity.inc. Hope this helps.

Chris Gillis’s picture

The problem I face is that I am working with various entity types, some that are ECK entities, and others like "user", etc.

Do I need to sniff somehow and serve either eck__entity__form, or entity_form() depending on the originating module?

sonictruth’s picture

Hey Chris,

I think what you want to do is add the ECK form callback to the entity info array using hook_entity_info_alter()

This is effectively what we did to add ECK support to Entity Dialog.

You can add anything you like to the entity info array and it will persist through to where ever you need it.

Something like this should do the trick for you.


<?php

function your_module_entity_info_alter(&$entity_info) {
  // Go through the entity info for each entity type on the system.
  foreach ($entity_info as $entity_type => $entity_type_info) {
    // These are the entity types that we want to add a form callback for.
    $add_form_callback_for = array('entity_type_a', 'entity_type_b');
    
    if (in_array($entity_type, $add_form_callback_for)) {
      $entity_info[$entity_type]['form callback'] = 'eck__entity__form';
    }
  }
}

?>

All that being said it would be great—if there are any ECK maintainers watching—for ECK to do this itself thereby enabling us to use the nice functions that the entity module provides in conjunction with ECK out of the box.

fmizzell’s picture

Version: 7.x-2.0-rc2 » 7.x-3.x-dev
Status: Active » Closed (fixed)

and backported to 2.x