1 entity_example.module entity_example_basic_form($form, &$form_state, $entity)

Form function to create an entity_example_basic entity.

The pattern is:

  • Set up the form for the data that is specific to your entity: the columns of your base table.
  • Call on the Field API to pull in the form elements for fields attached to the entity.

Related topics

File

modules/examples/entity_example/entity_example.module, line 409
Hook implementations for the Entity Example module.

Code

function entity_example_basic_form($form, &$form_state, $entity) {
  $form['item_description'] = array(
    '#type' => 'textfield',
    '#title' => t('Item Description'),
    '#required' => TRUE,
    '#default_value' => $entity->item_description,
  );

  $form['basic_entity'] = array(
    '#type' => 'value',
    '#value' => $entity,
  );

  field_attach_form('entity_example_basic', $entity, $form, $form_state);

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 100,
  );
  $form['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#submit' => array('entity_example_basic_edit_delete'),
    '#weight' => 200,
  );

  return $form;
}