You are here

public function UCXF_Field::edit_form in Extra Fields Checkout Pane 6.2

Same name and namespace in other branches
  1. 7 class/UCXF_Field.class.php \UCXF_Field::edit_form()

Get the edit form for the field. @access public

Return value

array

1 call to UCXF_Field::edit_form()
UCXF_AddressField::edit_form in class/UCXF_AddressField.class.php
Override of UCXF_Field::edit_form().
1 method overrides UCXF_Field::edit_form()
UCXF_AddressField::edit_form in class/UCXF_AddressField.class.php
Override of UCXF_Field::edit_form().

File

class/UCXF_Field.class.php, line 337
Contains the UCXF_Field class.

Class

UCXF_Field
Base class for a Extra Fields Pane field

Code

public function edit_form() {
  $form = array(
    '#tree' => TRUE,
  );

  // Add instance of this to the form
  $form['field'] = array(
    '#type' => 'value',
    '#value' => $this,
  );
  if (!empty($this->field_id)) {
    $form['ucxf']['field_id'] = array(
      '#type' => 'hidden',
      '#value' => $this->field_id,
    );
    drupal_set_title(t('Modify field: %name', array(
      '%name' => $this->db_name,
    )));
  }
  $form['ucxf']['label'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#size' => 25,
    '#description' => t('Label shown to customers in checkout pages.'),
    '#required' => TRUE,
    '#default_value' => $this->label,
    '#weight' => 0,
  );
  $default_db_name = $this->db_name;
  if (strpos($default_db_name, 'ucxf_') !== 0) {
    $default_db_name = 'ucxf_';
  }
  $form['ucxf']['db_name'] = array(
    '#title' => t('Field name'),
    '#type' => 'textfield',
    '#size' => 25,
    '#description' => t('Database field name. It must contain only lower chars a-z, digits 0-9 and _. Max allowed length is !number characters. This is inclusive the prefix %prefix.', array(
      '!number' => 32,
      '%prefix' => 'ucxf_',
    )),
    '#required' => TRUE,
    '#default_value' => $this->db_name,
    '#weight' => 1,
    '#maxlength' => 32,
  );
  if (isset($this->field_id)) {

    // if field already exists, don't allow to alter the name
    $form['ucxf']['db_name']['#disabled'] = 'disabled';
    $form['ucxf']['db_name']['#value'] = $this->db_name;
  }
  $form['ucxf']['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textarea',
    '#rows' => 3,
    '#description' => t('Insert a description to tell customers how to fill this field. ONLY applies for select/textbox options'),
    '#default_value' => $this->description,
    '#weight' => 3,
  );
  $form['ucxf']['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#delta' => 30,
    '#default_value' => $this->weight,
    '#description' => t('The listing position to display the order data on checkout/order panes.'),
    '#weight' => 5,
  );
  $form['ucxf']['pane_type'] = array(
    '#title' => t('Select which pane you would like the form value to be hooked into.'),
    '#type' => 'select',
    '#options' => array(
      'extra_information' => t('Extra Information pane'),
    ),
    '#default_value' => $this->pane_type,
    '#weight' => 7,
  );
  $value_type_options = array(
    self::UCXF_WIDGET_TYPE_TEXTFIELD => array(
      '#title' => t('Textfield'),
      '#description' => t('Let the user input the data in a textbox. If you want a default value, put it in "value" field below.'),
    ),
    self::UCXF_WIDGET_TYPE_SELECT => array(
      '#title' => t('Select list'),
      '#description' => t('Let the user select from a list of options (enter one <strong>safe_key|Some readable option</strong> per line).'),
    ),
    self::UCXF_WIDGET_TYPE_CHECKBOX => array(
      '#title' => t('Checkbox'),
      '#description' => t('Let the user select from a checkbox.'),
    ),
    self::UCXF_WIDGET_TYPE_CONSTANT => array(
      '#title' => t('Constant'),
      '#description' => t('Show a admin defined constant value, insert the value in the "value" section.'),
    ),
  );
  if (user_access('use php fields')) {
    $value_type_options += array(
      self::UCXF_WIDGET_TYPE_PHP => array(
        '#title' => t('PHP string'),
        '#description' => t('Set the value to the php code that returns a <code>STRING</code> (PHP-mode, experts only).'),
      ),
      self::UCXF_WIDGET_TYPE_PHP_SELECT => array(
        '#title' => t('PHP select list'),
        '#description' => t('Let the user select from a list of options from php code returning a <code>ARRAY</code> of key => value pairs. ie- <code>return array(\'element1\' => \'somevalue1\',\'element2\' => \'somevalue2\')</code> (PHP-mode, experts only).'),
      ),
    );
  }
  $form['ucxf']['value_type'] = array(
    '#type' => 'radios',
    '#title' => t('Field type'),
    '#options' => $value_type_options,
    '#default_value' => $this->value_type,
    '#weight' => 9,
    '#required' => TRUE,
    '#after_build' => array(
      'uc_extra_fields_pane_field_value_type_after_build',
    ),
  );
  $form['ucxf']['value'] = array(
    '#type' => 'textarea',
    '#title' => t('Value'),
    '#description' => t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array(
      '%php' => '<?php ?>',
    )),
    '#default_value' => $this->value,
    '#weight' => 10,
  );
  $form['ucxf']['required'] = array(
    '#title' => t('Field required'),
    '#type' => 'checkbox',
    '#description' => t('Check this item if the field is mandatory.'),
    '#default_value' => $this->required,
    '#weight' => 12,
  );
  $display_options = module_invoke_all('ucxf_display_options', $this);
  $form['ucxf']['display_settings'] = array(
    '#title' => t('Display options'),
    '#type' => 'fieldset',
    '#weight' => 14,
    '#description' => t('Choose on which pages you want to display the field.'),
  );
  foreach ($display_options as $option_id => $option) {
    $form['ucxf']['display_settings'][$option_id] = array(
      '#title' => $option_id,
      '#type' => 'checkbox',
      '#default_value' => $this
        ->may_display($option_id),
    );
    foreach ($option as $attribute_name => $attribute_value) {
      switch ($attribute_name) {
        case 'title':
          $form['ucxf']['display_settings'][$option_id]['#title'] = $attribute_value;
          break;
        case 'description':
          $form['ucxf']['display_settings'][$option_id]['#description'] = $attribute_value;
          break;
        case 'weight':
          $form['ucxf']['display_settings'][$option_id]['#weight'] = $attribute_value;
          break;
      }
    }
  }
  $form['ucxf']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 50,
  );
  if ($this->returnpath) {

    // Add 'cancel'-link
    $form['ucxf']['submit']['#suffix'] = l(t('Cancel'), $this->returnpath);
  }
  return $form;
}