You are here

function eck__entity_type__form in Entity Construction Kit (ECK) 7.3

Same name and namespace in other branches
  1. 7 eck.entity_type.inc \eck__entity_type__form()
  2. 7.2 eck.entity_type.inc \eck__entity_type__form()

Entity type form callback.

Parameters

string $entity_type_name: (optional) The machine name of the entity type to edit. If omitted, the form is presented for adding a new entity type.

2 string references to 'eck__entity_type__form'
eck__bundle__menu in ./eck.bundle.inc
This function creates the menu items relevant to bundle administration.
eck__entity_type__menu in ./eck.entity_type.inc
Passthrough from hook_menu().

File

./eck.entity_type.inc, line 117
ENTITY TYPE

Code

function eck__entity_type__form($form, &$state, $entity_type_name = NULL) {

  // If this form is being called on a new entity, create a new entity type
  // object, otherwise load the corresponding entity type.
  if (!isset($entity_type_name)) {
    $entity_type = new EntityType();
  }
  else {
    $entity_type = EntityType::loadByName($entity_type_name);
  }
  $form['entity_type'] = array(
    '#type' => 'value',
    '#value' => $entity_type,
  );
  $form['entity_type_label'] = array(
    '#type' => 'textfield',
    '#title' => t('Entity Type'),
    '#default_value' => $entity_type->label,
    '#description' => t('A human readable name for the entity type'),
    '#required' => TRUE,
    '#disabled' => !$entity_type->is_new,
  );
  $form['entity_type_name'] = array(
    '#type' => 'machine_name',
    '#default_value' => $entity_type->name,
    '#disabled' => !$entity_type->is_new,
    '#machine_name' => array(
      'exists' => '_eck_fake_exists',
      'source' => array(
        'entity_type_label',
      ),
    ),
  );
  $form['#validate'][] = 'eck__entity_type__form_validate';

  // Only allow entering the desired bundle name when creating a new entity.
  if ($entity_type->is_new) {
    $form['bundle_label'] = array(
      '#type' => 'textfield',
      '#title' => 'Bundle (optional)',
      '#description' => 'A bundle with the same name as the entity type is created by default, this will override the default',
    );
    $form['bundle_name'] = array(
      '#type' => 'machine_name',
      '#required' => FALSE,
      '#machine_name' => array(
        'exists' => '_eck_fake_exists',
        'source' => array(
          'bundle_label',
        ),
      ),
    );
  }
  $form = eck__default_properties__form($form, $state, $entity_type);
  $form['submit'] = array(
    '#type' => 'submit',
    '#weight' => 10000,
    '#value' => t('Save'),
  );
  return $form;
}