You are here

function sweaver_property_form in Sweaver 7

Same name and namespace in other branches
  1. 6 plugins/sweaver_plugin_editor/sweaver_plugin_editor.admin.inc \sweaver_property_form()

Property new/edit form.

File

plugins/sweaver_plugin_editor/sweaver_plugin_editor.admin.inc, line 488
Administrative functions for Sweaver.

Code

function sweaver_property_form(&$form, $property = NULL) {
  if (empty($property)) {
    $property = new stdClass();
    $property->name = '';
    $property->property = '';
    $property->property_parent = '';
    $property->description = '';
    $property->property_type = '';
    $property->property_prefix = '';
    $property->property_suffix = '';
    $property->property_slider_min = 1;
    $property->property_slider_max = 72;
    $property->property_options = array();
    $property->export_type = 1;
  }
  if (!isset($property->oid)) {
    $property->oid = NULL;
  }

  // Parents.
  $parents = array(
    '' => '',
  );
  $all_properties = sweaver_object_load(NULL, 'property', 'all');
  foreach ($all_properties as $key => $prop) {
    if ($prop->property_type == 'parent') {
      $parents[$key] = $prop->description;
    }
  }
  $form['#object_type'] = 'property';
  $form['check_name'] = array(
    '#type' => 'value',
    '#value' => $property->export_type == 1 && !isset($property->oid) ? TRUE : FALSE,
  );
  $form['oid'] = array(
    '#type' => 'value',
    '#value' => $property->oid,
  );
  $form['name'] = array(
    '#title' => t('Machine name'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => $property->name,
    '#description' => t('The machine-readable name of this property. This name must contain only lowercase letters, numbers, underscores or hyphens and must be unique.'),
  );
  $form['property'] = array(
    '#title' => t('CSS property'),
    '#type' => 'textfield',
    '#required' => FALSE,
    '#default_value' => $property->property,
    '#description' => t('The actual CSS property. Seperate multiple values by spaces. This value can be empty for parent items.'),
  );
  $form['property_parent'] = array(
    '#title' => t('Parent'),
    '#type' => 'select',
    '#options' => $parents,
    '#default_value' => $property->property_parent,
    '#description' => t('The parent of this property. Eg, padding-top should have a parent called padding.'),
  );
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => $property->description,
    '#description' => t('Description of this property which will be used in the editor.'),
  );
  $form['property_prefix'] = array(
    '#title' => t('Prefix'),
    '#type' => 'textfield',
    '#default_value' => $property->property_prefix,
    '#description' => t('Prefix of this property.'),
  );
  $form['property_suffix'] = array(
    '#title' => t('Suffix'),
    '#type' => 'textfield',
    '#default_value' => $property->property_suffix,
    '#description' => t('Suffix of this property.'),
  );
  $types = array(
    'parent' => t('Parent'),
    'slider' => t('Slider'),
    'select' => t('Select'),
    'color' => t('Color'),
    'image' => t('Image'),
    'radio' => t('Radio'),
    'checkbox' => t('Checkbox'),
  );
  $form['property_type'] = array(
    '#title' => t('Type'),
    '#type' => 'select',
    '#options' => $types,
    '#default_value' => $property->property_type,
    '#description' => t('Selection type of this property. A parent can have children underneath, grouping other stuff together.'),
  );
  $form['property_slider_min'] = array(
    '#title' => t('Slider minimum'),
    '#type' => 'textfield',
    '#default_value' => $property->property_slider_min,
    '#description' => t('Minimum value for the slider, only applicable for the slider.'),
  );
  $form['property_slider_max'] = array(
    '#title' => t('Slider maximum'),
    '#type' => 'textfield',
    '#default_value' => $property->property_slider_max,
    '#description' => t('Maximum value for the slider, only applicable for the slider.'),
  );
  $property_options = '';
  sweaver_export_check_serialized_keys($property);
  if (is_array($property->property_options)) {
    foreach ($property->property_options as $key => $value) {
      $property_options .= $key . '|' . $value . "\n";
    }
  }
  $form['property_options'] = array(
    '#title' => t('Options'),
    '#type' => 'textarea',
    '#default_value' => $property_options,
    '#description' => t('Options for this property. Enter options per line and separate key and value by |.'),
    '#wysiwyg' => FALSE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'sweaver_property_form_submit',
    ),
  );
  return $form;
}