[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/form_builder/includes/ -> form_builder.properties.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file form_builder.properties.inc
   5   * Implementations of hook_form_builder_properties in separate functions.
   6   */
   7  
   8  /**
   9   * Configuration form for the "key" property.
  10   *
  11   * The key property is special in that it's not actually part of the element,
  12   * but instead the array key that is used to reference the element in the
  13   * Form API structure.
  14   */
  15  function form_builder_property_key_form(&$form_state, $form_type, $element, $property) {
  16    $form = array();
  17  
  18    $form['key'] = array(
  19      '#title' => t('Form key'),
  20      '#type' => 'textfield',
  21      '#default_value' => $element['#key'],
  22      '#required' => TRUE,
  23      '#weight' => -9,
  24      '#element_validate' => array('form_builder_property_key_form_validate'),
  25    );
  26  
  27    return $form;
  28  }
  29  
  30  /**
  31   * Element validate function for the "key" property. Ensure safe characters.
  32   */
  33  function form_builder_property_key_form_validate($element, $form_state) {
  34    if (!preg_match('/^[a-z0-9_]+$/', $element['#value'])) {
  35      form_error($element, t('The form key may only contain lowercase alphanumeric characters and underscores.'));
  36    }
  37  
  38    // Check that the new key does not conflict with an existing key.
  39    if ($element['#value'] != $element['#default_value']) {
  40      $active_form = form_builder_active_form();
  41      $form = form_builder_cache_load($active_form['form_type'], $active_form['form_id']);
  42      $parents = $element['#parents'];
  43      array_pop($parents);
  44      $parents[] = $element['#value'];
  45      $key_exists = FALSE;
  46      foreach ($parents as $key) {
  47        if (isset($form[$key])) {
  48          $form = $form[$key];
  49          $key_exists = TRUE;
  50        }
  51        else {
  52          $key_exists = FALSE;
  53          break;
  54        }
  55      }
  56  
  57      if ($key_exists) {
  58        form_error($element, t('The form key %key is already in use.', array('%key' => $element['#value'])));
  59      }
  60    }
  61  
  62  }
  63  
  64  /**
  65   * Configuration form for the "title" property.
  66   */
  67  function form_builder_property_title_form(&$form_state, $form_type, $element, $property) {
  68    $form = array();
  69  
  70    $form['title'] = array(
  71      '#title' => t('Title'),
  72      '#type' => 'textfield',
  73      '#default_value' => $element['#title'],
  74      '#required' => TRUE,
  75      '#weight' => -10,
  76    );
  77  
  78    return $form;
  79  }
  80  
  81  /**
  82   * Configuration form for the "title_display" property.
  83   */
  84  function form_builder_property_title_display_form(&$form_state, $form_type, $element, $property) {
  85    $form = array();
  86  
  87    $form['title_display'] = array(
  88      '#form_builder' => array('property_group' => 'display'),
  89      '#title' => t('Title display'),
  90      '#type' => 'select',
  91      '#default_value' => $element['#title_display'],
  92      '#options' => array(
  93        'before' => t('Before'),
  94        'after' => t('After'),
  95        'invisible' => t('Invisible'),
  96        'attribute' => t('Attribute'),
  97      ),
  98      '#required' => TRUE,
  99      '#weight' => -10,
 100    );
 101  
 102    return $form;
 103  }
 104  
 105  
 106  /**
 107   * Configuration form for the "weight" property.
 108   *
 109   * This field is in the "hidden" builder group, meaning it's never shown in
 110   * the main editing interface. However, it's still there if editing without JS.
 111   */
 112  function form_builder_property_weight_form(&$form_state, $form_type, $element, $property) {
 113    $form = array();
 114  
 115    if (!isset($_REQUEST['js'])) {
 116      $form['weight'] = array(
 117        '#form_builder' => array('property_group' => 'hidden'),
 118        '#type' => 'textfield',
 119        '#size' => 6,
 120        '#title' => t('Weight'),
 121        '#default_value' => $element['#weight'],
 122      );
 123    }
 124  
 125    return $form;
 126  }
 127  
 128  /**
 129   * Configuration form for the "description" property.
 130   */
 131  function form_builder_property_description_form(&$form_state, $form_type, $element, $property) {
 132    $form = array();
 133  
 134    $form['description'] = array(
 135      '#title' => t('Description'),
 136      '#type' => 'textarea',
 137      '#default_value' => $element['#description'],
 138      '#weight' => 5,
 139    );
 140  
 141    return $form;
 142  }
 143  
 144  /**
 145   * Configuration form for the "disabled" property.
 146   */
 147  function form_builder_property_disabled_form(&$form_state, $form_type, $element, $property) {
 148    $form = array();
 149  
 150    $form['disabled'] = array(
 151      '#form_builder' => array('property_group' => 'display'),
 152      '#title' => t('Disabled (read-only)'),
 153      '#type' => 'checkbox',
 154      '#default_value' => $element['#disabled'],
 155      '#weight' => 12,
 156    );
 157  
 158    return $form;
 159  }
 160  
 161  /**
 162   * Configuration form for the "required" property.
 163   */
 164  function form_builder_property_required_form(&$form_state, $form_type, $element, $property) {
 165    $form = array();
 166  
 167    $form['required'] = array(
 168      '#form_builder' => array('property_group' => 'validation'),
 169      '#title' => t('Required'),
 170      '#type' => 'checkbox',
 171      '#default_value' => $element['#required'],
 172      '#weight' => -1,
 173    );
 174  
 175    return $form;
 176  }
 177  
 178  /**
 179   * Configuration form for the "options" property.
 180   */
 181  function form_builder_property_options_form(&$form_state, $form_type, $element, $property) {
 182    $form = array();
 183  
 184    // Checkboxes have an implied "multiple" property.
 185    if ($element['#type'] == 'checkboxes') {
 186      $element['#multiple'] = TRUE;
 187    }
 188  
 189    $form['options'] = array(
 190      '#form_builder' => array('property_group' => 'options'),
 191      '#title' => t('Options'),
 192      '#type' => 'options',
 193      '#default_value' => $element['#default_value'],
 194      '#options' => $element['#options'],
 195      '#required' => TRUE,
 196      '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : FALSE,
 197      '#multiple_toggle' => isset($element['#multiple_toggle']) ? $element['#multiple_toggle'] : FALSE,
 198      '#optgroups' => $element['#type'] == 'select' ? TRUE : FALSE,
 199      '#limit' => 100,
 200      '#key_type' => isset($element['#key_type']) ? $element['#key_type'] : 'mixed',
 201      '#key_type_toggle' => isset($element['#key_type_toggle']) ? $element['#key_type_toggle'] : TRUE,
 202      '#key_type_toggled' => isset($element['#key_type_toggled']) ? $element['#key_type_toggled'] : FALSE,
 203    );
 204  
 205    // Remove the default value field, since it's handled by the options field.
 206    $form['default_value'] = array();
 207  
 208    return $form;
 209  }
 210  
 211  function form_builder_property_options_form_submit(&$form, &$form_state) {
 212    $options = $form_state['values']['options']['options'];
 213    $default_value = $form_state['values']['options']['default_value'];
 214  
 215    if (isset($form_state['values']['options']['multiple'])) {
 216      $multiple = $form_state['values']['options']['multiple'];
 217      $form_state['values']['multiple'] = $multiple;
 218    }
 219  
 220    if (isset($form_state['values']['options']['custom_keys'])) {
 221      $form_state['values']['key_type_toggled'] = $form_state['values']['options']['custom_keys'];
 222    }
 223  
 224    $form_state['values']['options'] = $options;
 225    $form_state['values']['default_value'] = $default_value;
 226  }
 227  
 228  /**
 229   * Configuration form for the "default_value" property.
 230   */
 231  function form_builder_property_default_value_form(&$form_state, $form_type, $element, $property) {
 232    $form = array();
 233  
 234    $form['default_value'] = array(
 235      // Most fields have default values that can be stored on one line, so we
 236      // use a textfield to configure their default value. Textareas are an
 237      // exception, though.
 238      '#type' => $element['#type'] == 'textarea' ? 'textarea' : 'textfield',
 239      '#title' => t('Default value'),
 240      '#default_value' => $element['#default_value'],
 241      '#weight' => 1,
 242    );
 243  
 244    return $form;
 245  }
 246  
 247  /**
 248   * Configuration form for the "markup" property.
 249   */
 250  function form_builder_property_markup_form(&$form_state, $form_type, $element, $property) {
 251    $form = array();
 252  
 253    // TODO: This is a placeholder until "#markup" becomes available in D7.
 254    $form['markup'] = array(
 255      '#type' => 'textarea',
 256      '#title' => t('Markup'),
 257      '#default_value' => $element['#markup'],
 258      '#weight' => 1,
 259    );
 260  
 261    return $form;
 262  }
 263  
 264  /**
 265   * Configuration form for the "input_format" property.
 266   */
 267  function form_builder_property_input_format_form(&$form_state, $form_type, $element) {
 268    $form = array();
 269  
 270    // TODO: This is a placeholder until "#input_format" becomes available in D7.
 271    $format = isset($element['#input_format']) ? $element['#input_format'] : FILTER_FORMAT_DEFAULT;
 272    $form['input_format'] = filter_form($format, 2, array('input_format'));
 273  
 274    return $form;
 275  }
 276  
 277  /**
 278   * Configuration form for the "size" property.
 279   */
 280  function form_builder_property_size_form(&$form_state, $form_type, $element, $property) {
 281    $form = array();
 282  
 283    $form['size'] = array(
 284      '#form_builder' => array('property_group' => 'display'),
 285      '#type' => 'textfield',
 286      '#size' => 6,
 287      '#title' => t('Size'),
 288      '#default_value' => $element['#size'],
 289      '#weight' => 2,
 290    );
 291  
 292    return $form;
 293  }
 294  
 295  /**
 296   * Configuration form for the "rows" property.
 297   */
 298  function form_builder_property_rows_form(&$form_state, $form_type, $element, $property) {
 299    $form = array();
 300  
 301    $form['rows'] = array(
 302      '#form_builder' => array('property_group' => 'display'),
 303      '#type' => 'textfield',
 304      '#size' => 6,
 305      '#title' => t('Rows'),
 306      '#default_value' => $element['#rows'],
 307      '#weight' => 2,
 308    );
 309  
 310    return $form;
 311  }
 312  
 313  /**
 314   * Configuration form for the "cols" property.
 315   */
 316  function form_builder_property_cols_form(&$form_state, $form_type, $element, $property) {
 317    $form = array();
 318  
 319    $form['cols'] = array(
 320      '#form_builder' => array('property_group' => 'display'),
 321      '#type' => 'textfield',
 322      '#size' => 6,
 323      '#title' => t('Columns'),
 324      '#default_value' => $element['#cols'],
 325      '#weight' => 3,
 326      '#description' => t('The width of the textarea. This property might not have a visual impact depending on the CSS of your site.'),
 327    );
 328  
 329    return $form;
 330  }
 331  
 332  
 333  /**
 334   * Configuration form for the "field_prefix" property.
 335   */
 336  function form_builder_property_field_prefix_form(&$form_state, $form_type, $element, $property) {
 337    $form = array();
 338  
 339    $form['field_prefix'] = array(
 340      '#form_builder' => array('property_group' => 'display'),
 341      '#type' => 'textfield',
 342      '#title' => t('Prefix'),
 343      '#default_value' => $element['#field_prefix'],
 344      '#weight' => -2,
 345    );
 346  
 347    return $form;
 348  }
 349  
 350  /**
 351   * Configuration form for the "field_suffix" property.
 352   */
 353  function form_builder_property_field_suffix_form(&$form_state, $form_type, $element, $property) {
 354    $form = array();
 355  
 356    $form['field_suffix'] = array(
 357      '#form_builder' => array('property_group' => 'display'),
 358      '#type' => 'textfield',
 359      '#title' => t('Suffix'),
 360      '#default_value' => $element['#field_suffix'],
 361      '#weight' => -1,
 362    );
 363  
 364    return $form;
 365  }
 366  
 367  /**
 368   * Configuration form for the "collapsible" property.
 369   */
 370  function form_builder_property_collapsible_form(&$form_state, $form_type, $element, $property) {
 371    $form = array();
 372  
 373    $form['collapsible'] = array(
 374      '#form_builder' => array('property_group' => 'display'),
 375      '#type' => 'checkbox',
 376      '#title' => t('Collapsible'),
 377      '#default_value' => $element['#collapsible'],
 378      '#weight' => -2,
 379    );
 380  
 381    return $form;
 382  }
 383  
 384  /**
 385   * Configuration form for the "collapsed" property.
 386   */
 387  function form_builder_property_collapsed_form(&$form_state, $form_type, $element, $property) {
 388    $form = array();
 389  
 390    $form['collapsed'] = array(
 391      '#form_builder' => array('property_group' => 'display'),
 392      '#type' => 'checkbox',
 393      '#title' => t('Collapsed'),
 394      '#default_value' => $element['#collapsed'],
 395      '#weight' => -1,
 396      '#description' => t('This property will not affect the preview immediately.'),
 397    );
 398  
 399    return $form;
 400  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7