Commit 8119c5da authored by Dries's avatar Dries

- Patch #735662 by duellj, tstoeckler: critical bug: hook_form_alter() can...

- Patch #735662 by duellj, tstoeckler: critical bug: hook_form_alter() can easily clobber a text format.
parent 6987dd4c
......@@ -442,9 +442,9 @@ function block_add_block_form_validate($form, &$form_state) {
function block_add_block_form_submit($form, &$form_state) {
$delta = db_insert('block_custom')
->fields(array(
'body' => $form_state['values']['body'],
'body' => $form_state['values']['body']['value'],
'info' => $form_state['values']['info'],
'format' => $form_state['values']['format'],
'format' => $form_state['values']['body']['format'],
))
->execute();
// Store block delta to allow other modules to work with new block.
......
......@@ -469,8 +469,9 @@ function block_custom_block_form($edit = array()) {
* @param $edit
* Associative array of fields to save. Array keys:
* - info: Block description.
* - body: Block contents.
* - format: Filter ID of the filter format for the body.
* - body: Associative array of body value and format. Array keys:
* - value: Block contents.
* - format: Filter ID of the filter format for the body.
* @param $delta
* Block ID of the block to save.
* @return
......@@ -479,9 +480,9 @@ function block_custom_block_form($edit = array()) {
function block_custom_block_save($edit, $delta) {
db_update('block_custom')
->fields(array(
'body' => $edit['body'],
'body' => $edit['body']['value'],
'info' => $edit['info'],
'format' => $edit['format'],
'format' => $edit['body']['format'],
))
->condition('bid', $delta)
->execute();
......
......@@ -730,29 +730,12 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)
* the text format id specified in #format or the user's default format by
* default, if NULL.
*
* Since most modules expect the value of the new 'format' element *next* to the
* original element, filter_process_format() utilizes an #after_build to move
* the values of the children of the 'text_format' element so as to let the
* submitted form values appear as if they were located on the same level.
* For example, considering the input values:
* The resulting value for the element will be an array holding the value and the
* format. For example, the value for the body element will be:
* @code
* $form_state['input']['body']['value'] = 'foo';
* $form_state['input']['body']['format'] = 'foo';
* $form_state['values']['body']['value'] = 'foo';
* $form_state['values']['body']['format'] = 'foo';
* @endcode
* The #after_build will process them into:
* @code
* $form_state['values']['body'] = 'foo';
* $form_state['values']['format'] = 'foo';
* @endcode
*
* If multiple text format-enabled elements are required on the same level of
* the form structure, modules can set custom #parents on the original element.
* Alternatively, the #after_build may be unset through a subsequent #process
* callback. If the default #after_build is not invoked and no custom processing
* occurs, then the submitted form values will appear like in the
* $form_state['input'] array above.
*
* @see filter_form_after_build()
*
* @param $element
* The form element to process. Properties used:
......@@ -804,9 +787,6 @@ function filter_process_format($element) {
$element['#attached']['js'][] = $path . '/filter.js';
$element['#attached']['css'][] = $path . '/filter.css';
// Apply default #after_build behavior.
$element['#after_build'][] = 'filter_form_after_build';
// Setup child container for the text format widget.
$element['format'] = array(
'#type' => 'fieldset',
......@@ -886,38 +866,6 @@ function filter_process_format($element) {
return $element;
}
/**
* After build callback to move #type 'text_format' values up in $form_state.
*/
function filter_form_after_build($element, &$form_state) {
// For text fields, the additional subkeys map 1:1 to field schema columns.
if (isset($element['#columns'])) {
return $element;
}
$parents = $element['#parents'];
array_pop($parents);
foreach (element_children($element) as $key) {
$current_parents = $parents;
switch ($key) {
case 'value':
form_set_value(array('#parents' => $element['#parents']), $element[$key]['#value'], $form_state);
break;
case 'format':
$current_parents[] = $key;
form_set_value(array('#parents' => $current_parents), $element['format']['format']['#value'], $form_state);
break;
default:
$current_parents[] = $key;
form_set_value(array('#parents' => $current_parents), $element[$key]['#value'], $form_state);
}
}
return $element;
}
/**
* #pre_render callback for #type 'text_format' to hide field value from prying eyes.
*
......
......@@ -837,6 +837,12 @@ function taxonomy_form_term_submit($form, &$form_state) {
*/
function taxonomy_form_term_submit_builder($form, &$form_state) {
$term = (object) $form_state['values'];
// Convert text_format field into values expected by taxonomy_term_save().
$description = $form_state['values']['description'];
$term->description = $description['value'];
$term->format = $description['format'];
field_attach_submit('taxonomy_term', $term, $form, $form_state);
$form_state['term'] = (array) $term;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment