You are here

function _formdefaults_get_field in Form Defaults 5.3

Same name and namespace in other branches
  1. 8 formdefaults.module \_formdefaults_get_field()
  2. 5 formdefaults.module \_formdefaults_get_field()
  3. 5.2 formdefaults.module \_formdefaults_get_field()
  4. 6.2 formdefaults.module \_formdefaults_get_field()
  5. 6 formdefaults.module \_formdefaults_get_field()
  6. 7 formdefaults.module \_formdefaults_get_field()

Recursively iterate through the form array to save titles and descirptions. The the resulting title/description array is intentionally flattened to make indexing easier during the "replacement" portion of the code. Also tack on the [edit] link.

Parameters

$formid the formid of the form we're altering:

$fieldname the fieldname of the last form field we found.:

$fieldvalue The array of field values that we found last.:

$fieldarray We store the array of titles and desciptions in this array for storing later.:

1 call to _formdefaults_get_field()
formdefaults_form_alter in ./formdefaults.module
implements hook_form_alter

File

./formdefaults.module, line 160

Code

function _formdefaults_get_field($formid, $fieldname, &$fieldvalue, &$fieldarray) {
  if (is_array($fieldvalue) && !(strpos($fieldname, '#') === 0)) {

    // Determine return location for links.
    $query = array();
    $query['destination'] = $_GET['q'];
    $query = drupal_query_string_encode($query);
    $type = $fieldvalue['#type'];
    $fieldarray[$fieldname]['type'] = $type;

    // Skip submit and hidden fields cause they're too dangerous to alter.
    if ($type != 'submit' && $type != 'hidden' && $type != 'value') {
      if (array_key_exists('#weight', $fieldvalue)) {
        $fieldarray[$fieldname]['weight'] = $fieldvalue['#weight'];
      }
      else {
        $fieldarray[$fieldname]['weight'] = 'unset';
      }
      if ($type == 'markup') {
        $fieldarray[$fieldname]['value'] = $fieldvalue['#value'];
        $fieldvalue['#value'] = l('[' . t('edit markup') . ']', 'formdefaults/' . $formid . '/' . $fieldname, null, $query) . ' ' . $fieldvalue['#value'];
      }
      else {
        $fieldarray[$fieldname]['title'] = $fieldvalue['#title'];
        $fieldarray[$fieldname]['description'] = $fieldvalue['#description'];
        $fieldvalue['#description'] = l('[' . t('edit @type', array(
          '@type' => $fieldvalue['#type'],
        )) . ']', 'formdefaults/' . $formid . '/' . $fieldname, null, $query) . ' ' . $fieldvalue['#description'];
      }
    }
    foreach ($fieldvalue as $key => $value) {
      if (!(strpos($key, '#') === 0)) {
        _formdefaults_get_field($formid, $key, $fieldvalue[$key], $fieldarray);
      }
    }
  }
}