function _formdefaults_get_field in Form Defaults 8
Same name and namespace in other branches
- 5.3 formdefaults.module \_formdefaults_get_field()
- 5 formdefaults.module \_formdefaults_get_field()
- 5.2 formdefaults.module \_formdefaults_get_field()
- 6.2 formdefaults.module \_formdefaults_get_field()
- 6 formdefaults.module \_formdefaults_get_field()
- 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 95
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'] = \Drupal::request()->attributes
->get('_system_path');
if (is_array($query)) {
$query = UrlHelper::buildQuery($query);
$options['query'] = $query;
}
$options = array();
$type = @$fieldvalue['#type'];
$fieldarray[$fieldname]['type'] = $type;
// Skip submit and hidden fields cause they're too dangerous to alter.
if ($type != 'submit' && $type != 'hidden') {
if (array_key_exists('#weight', $fieldvalue)) {
$fieldarray[$fieldname]['weight'] = $fieldvalue['#weight'];
}
else {
$fieldarray[$fieldname]['weight'] = 'unset';
}
if ($type == 'markup') {
$link = Link::createFromRoute('[' . t('edit markup') . ']', 'formdefaults.edit', [
'formid' => $formid,
'field' => $fieldname,
])
->toString();
$fieldarray[$fieldname]['value'] = @$fieldvalue['#markup'];
$fieldvalue['#markup'] = $link . ' ' . @$fieldvalue['#markup'];
}
else {
$fieldarray[$fieldname]['title'] = @$fieldvalue['#title'];
$fieldarray[$fieldname]['description'] = @$fieldvalue['#description'];
$fieldvalue['#suffix'] = Link::createFromRoute('[' . t('edit @type', [
'@type' => @$fieldvalue['#type'],
]) . ']', 'formdefaults.edit', [
'formid' => $formid,
'field' => $fieldname,
])
->toString();
}
}
foreach ($fieldvalue as $key => $value) {
if (!(strpos($key, '#') === 0)) {
_formdefaults_get_field($formid, $key, $fieldvalue[$key], $fieldarray);
}
}
}
}