You are here

function eck__property_add__form in Entity Construction Kit (ECK) 7.3

Add property form.

1 string reference to 'eck__property_add__form'
eck__bundle__menu in ./eck.bundle.inc
This function creates the menu items relevant to bundle administration.

File

./eck.properties.inc, line 115
Properties.

Code

function eck__property_add__form($form, &$state, $entity_type_name) {
  $form['entity_type_name'] = array(
    '#type' => 'value',
    '#value' => $entity_type_name,
  );

  // Add new property.
  $property_types = eck_get_property_types();

  // Lets transform the property_types info array into something appropriate
  // for a select list.
  $property_type_options = array();
  foreach ($property_types as $property_name => $info) {
    $property_type_options[$property_name] = $info['label'];
  }
  $types[t('Generic')] = $property_type_options;
  $form["add_new_property"] = array(
    '#markup' => '<h3>Add new property</h3>',
  );
  $form['property_type'] = array(
    '#type' => 'select',
    '#title' => t('Type'),
    '#options' => array(
      '' => t('- Please choose -'),
    ) + $types,
    '#required' => TRUE,
  );
  $form['property_select_type'] = array(
    '#type' => 'submit',
    '#value' => t('Select Property Type'),
  );
  if (array_key_exists('values', $state) && !empty($state['values']['property_type'])) {
    $property_type = $state['values']['property_type'];
    $property_type_info = eck_get_property_types($property_type);
    $default_schema = $property_type_info['class']::schema();
    $form['default_schema'] = array(
      '#type' => 'value',
      '#value' => $default_schema,
    );
    $sf = new SchemaForm($default_schema);
    $schema_form = $sf
      ->getSchemaForm();
    foreach ($schema_form as $name => $field) {
      unset($schema_form[$name]);
      $schema_form["schema_{$name}"] = $field;
    }
    $form['schema'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => 'Schema Configuration',
    );
    $form['schema']['form'] = $schema_form;
    $form["property_label"] = array(
      '#type' => 'textfield',
      '#title' => t("Name"),
      '#description' => t("A human readable name for the property."),
      '#required' => TRUE,
      '#after_build' => array(
        '_eck_deactivate_on_save',
      ),
    );
    $form["property_name"] = array(
      '#type' => 'machine_name',
      '#machine_name' => array(
        'exists' => '_eck_fake_exists',
        'source' => array(
          'property_label',
        ),
      ),
      '#after_build' => array(
        '_eck_deactivate_on_save',
      ),
    );
    $form['property_add'] = array(
      '#type' => 'submit',
      '#value' => t('Add Property'),
    );
  }
  return $form;
}