You are here

function eck__bundle__edit_form in Entity Construction Kit (ECK) 7.2

Same name and namespace in other branches
  1. 7.3 eck.bundle.inc \eck__bundle__edit_form()

Form constructor for the entity bundle editing form.

Parameters

string $entity_type_name: Entity type name.

string $bundle_name: Entity bundle name.

1 string reference to 'eck__bundle__edit_form'
eck__entity__menu in ./eck.entity.inc
Entity related menu items.

File

./eck.bundle.inc, line 329

Code

function eck__bundle__edit_form($form, &$form_state, $entity_type_name, $bundle_name) {
  $path = eck__entity_type__path();
  $entity_type = entity_type_load($entity_type_name);
  $bundle = bundle_load($entity_type_name, $bundle_name);
  $form = array();
  $form['entity_type'] = array(
    '#type' => 'value',
    '#value' => $entity_type,
  );
  $form['bundle'] = array(
    '#type' => 'value',
    '#value' => $bundle,
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => $bundle->label,
    '#required' => TRUE,
  );

  // Create a list of properties for this bundle.
  $properties = array();
  foreach ($entity_type->properties as $property => $info) {
    $properties[$property] = $property . ' (' . $info['label'] . ')';
  }

  // Determine which managed fields should be checked by default.
  $default_properties = !empty($bundle->config['managed_properties']) && is_array($bundle->config['managed_properties']) ? array_intersect_key($bundle->config['managed_properties'], $properties) : array();

  // Add configuration to manage property display through the manage field
  // forms.
  $form['config_managed_properties'] = array(
    '#type' => 'checkboxes',
    '#options' => $properties,
    '#default_value' => $default_properties,
    '#title' => t('Managed Properties'),
    '#description' => t('Select the properties you would like to be able to manage like fields through the "Manage Fields" and "Display Fields" tabs on this Bundle.'),
  );

  // Let the behaviors to modify form.
  $vars = eck_property_behavior_invoke_plugin_alter($entity_type, 'bundle_form', array(
    'form' => $form,
    'form_state' => $form_state,
  ));
  $form = $vars['form'];
  $form_state = $vars['form_state'];
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save bundle'),
    '#weight' => 40,
  );
  return $form;
}