function formdefaults_alterform in Form Defaults 6.2
Same name and namespace in other branches
- 8 formdefaults.module \formdefaults_alterform()
- 5.3 formdefaults.module \formdefaults_alterform()
- 5 formdefaults.module \formdefaults_alterform()
- 5.2 formdefaults.module \formdefaults_alterform()
- 6 formdefaults.module \formdefaults_alterform()
- 7 formdefaults.module \formdefaults_alterform()
Alters the form based on the form replacement items passed.
Parameters
$formid the form id of the form that we're altering:
$fieldname the field name of the last field we found:
$fieldvalues the field value array form the last field we found.:
$formreplace the replacement data for the form. :
1 call to formdefaults_alterform()
- formdefaults_form_alter in ./
formdefaults.module - implements hook_form_alter
File
- ./
formdefaults.module, line 234
Code
function formdefaults_alterform($formid, $fieldname, &$fieldvalue, $formreplace) {
// Determine return location for links.
$query = array();
$query['destination'] = $_GET['q'];
$query = drupal_query_string_encode($query);
$enabled = $_SESSION['formdefaults_enabled'] && $formid != 'formdefaults_edit';
// Need to make sure we aren't processing attributes.
if (is_array($fieldvalue) && !(strpos($fieldname, '#') === 0)) {
if (is_array($formreplace[$fieldname])) {
// perform the replacement.
// fo stands for field override
$fo = $formreplace[$fieldname];
if ($formreplace[$fieldname]['hide_it']) {
_formdefaults_hide_recursive($fieldvalue);
}
if ($fo['weight'] != 'unset') {
$fieldvalue['#weight'] = $fo['weight'];
}
if ($fieldvalue['#type'] == 'fieldset' && array_key_exists('collapsible', $fo)) {
$fieldvalue['#collapsible'] = $fo['collapsible'];
}
if ($fieldvalue['#type'] == 'fieldset' && array_key_exists('collapsed', $fo)) {
$fieldvalue['#collapsed'] = $fo['collapsed'];
}
if ($fieldvalue['#type'] == 'markup') {
$fieldvalue['#value'] = check_markup($formreplace[$fieldname]['value'], $formreplace[$fieldname]['format'], false);
}
else {
$fieldvalue['#title'] = $fo['title'];
$fieldvalue['#description'] = $fo['description'];
}
// add back on the edit control if appropriate.
if (user_access('change form labels') && $enabled) {
if ($fieldvalue['#type'] != 'markup') {
$fieldvalue['#description'] = l('[' . t('edit') . ' ' . t($fieldvalue['#type']) . ']', 'formdefaults/' . $formid . '/' . $fieldname, array(
'query' => $query,
)) . ' ' . $fieldvalue['#description'];
}
else {
$fieldvalue['#value'] = l('[' . t('edit markup') . ']', 'formdefaults/' . $formid . '/' . $fieldname, array(
'query' => $query,
)) . ' ' . $fieldvalue['#value'];
}
}
}
// If this is a fieldset, we're going to need to recurse.
foreach ($fieldvalue as $key => $value) {
if (!(strpos($key, '#') === 0)) {
formdefaults_alterform($formid, $key, $fieldvalue[$key], $formreplace);
}
}
}
}