For the Automatic Entity Label project it would be useful to know the following bits of information about entities:

  • What form is used for creating/editing an entity bundle (form id)?
  • What form is used for creating/editing an entity itself (form id)?
  • Is the entity label displayed or hidden by default?

Is the entity api the right place for discussing the possibility of adding such information to entity info?

Comments

bojanz’s picture

#1196456: provide a harmonized entity_form() function should solve some of your questions.

bforchhammer’s picture

I am sorry, but I don't understand how that helps... would you mind elaborating?

For clarification: I'm looking for a way to be able to modify existing forms... i.e. my idea was to implement hook_form_alter() and use the form id to check whether a form is one that I would like to adjust. E.g. for bundle edit forms, the form ids would be:

  • Nodes: node_type_form
  • Comments: node_type_form
  • Taxonomy Vocabularies: taxonomy_form_vocabulary
  • Profile2: profile2_type_form

There doesn't seem to be a consistent pattern here, especially with things like node+comment configuration using the same form. Also, I'd not only like to know if a form belongs to the class of "bundle edit forms", but also which entities/bundles it's for, i.e. in the case of node_type_form I'd want to know that it is responsible for configuration of both comment and nodetype entities.

I could of course just hard-code some of these ids, but where's the fun in that? (Also, maybe the mapping of entity-type + bundle --> form id could be useful to other developers as well) ;-)

Sorry, if this is already possible and I just haven't figured it out...

fmizzell’s picture

function entity_form($entity_type, $entity) {
  $info = entity_get_info($entity_type);
  if (isset($info['form callback'])) {
    return $info['form callback']($entity, $entity_type);
  }
  // If there is an UI controller, the providing module has to implement the
  // entity form using entity_ui_get_form().
  elseif (entity_ui_controller($entity_type)) {
    return entity_metadata_form_entity_ui($entity, $entity_type);
  }
  return FALSE;
}

This is the piece of code from the issue bojanz pointed out.

As you can see this entity_form function is looking for a 'form callback' key in the entity_info array. This info will help you with entity forms, but not with the other two cases:

  1. forms that affect entities of a particular bundle
  2. forms to manipulate bundles themselves

I guess following the pattern set up by that issue there should also be a 'form callback' at $entity_info[$entity_type]['bundles'][$bundle] to cover the second case.

For the first case, have you ran into any of these? Which module have forms that are exclusively for an entity_type+bundle pair.. I don't believe core has any of those.

not sure where the node+comment info needs to be added.

bforchhammer’s picture

This info will help you with entity forms

I still don't see how exactly. The form callback is not the same as the form id, i.e. this will not help me with hook_form_alter() as far as I can see. entity_form() also doesn't provide any other means for altering a form...

fmizzell’s picture

That's true... well, I guess "form id" is needed in the info array too

bforchhammer’s picture

Related issue for identifying "entity forms": #1608838: Identifying entity edit forms