function _flashnode_form_after_build in Flash Node 5.2
Same name and namespace in other branches
- 5.6 flashnode.module \_flashnode_form_after_build()
- 5.3 flashnode.module \_flashnode_form_after_build()
Implementation of hook_after_build to perform some form processing
Various functions to manipulate the form after building in case default values are being reset. It also changes the description on the flash file field when a file has been uploaded, to help the user to identify which file is in use on this node. #parents is used as the identifier in case the title is being translated. Not sure if this is the right way to achieve this, but it appears to work!
This function is also used to set the substitution text to !default when the form is first opened, but to then allow the user to submit blanks if they don't want any substitution to appear. If you just use $node->flashnode['substitution'] ? $node->flashnode['substitution'] : '!default' then a blank substitution is treated as an undefined node and !default gets put in, when the blank is in fact a valid value.
1 string reference to '_flashnode_form_after_build'
- flashnode_form in ./
flashnode.module - Implementation of hook_form
File
- ./
flashnode.module, line 937
Code
function _flashnode_form_after_build($form, $form_values) {
// Change file upload description to reflect current upload if there is one
if (!empty($form_values['flashnode']['_flashnode']) && $form['#parents'][0] == 'flashfile') {
$form['#description'] = t('Current file is %filename. Click "Browse..." to upload a different file.', array(
'%filename' => basename($form_values['flashnode']['_flashnode']),
));
}
// If width field is empty then reset it to the default width
if (empty($form_values['flashnode']['width']) && $form['#parents'][1] == 'width') {
$form['#value'] = $form_values['flashnode']['_width'];
form_set_value($form, $form_values['flashnode']['_width']);
}
// If height field is empty then reset it to the default height
if (empty($form_values['flashnode']['height']) && $form['#parents'][1] == 'height') {
$form['#value'] = $form_values['flashnode']['_height'];
form_set_value($form, $form_values['flashnode']['_height']);
}
// If there is no flash file name, set substitution text to !default as this is a new form, provided there
// isn't currently anything in the substitution area (in case user made an error and only partially completed
// the form) We do it this way so that the user can have a blank without that being over-ridden by !default
if (empty($form_values['flashnode']['_flashnode']) && $form['#parents'][1] == 'substitution' && empty($form_values['flashnode']['substitution'])) {
$form['#value'] = '!default';
form_set_value($form, '!default');
}
// Return the amended form element
return $form;
}