function faqfield_field_presave in FAQ Field 7
Implements hook_field_presave().
Prepare formatable textarea values for saving them into the database.
File
- ./
faqfield.module, line 645 - FAQ Field Provides a field for frequently asked questions.
Code
function faqfield_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $key => &$values) {
if (is_array($values['answer'])) {
// Normal textarea's and textfields put their values simply in by
// array($name => $value); Unfortunately text_format textareas put
// them into an array so also the format gets saved: array($name
// => array('value' => $value, 'format' => $format)).
// So the API will try to save normal textfields to the 'name' field
// and text_format fields to 'answer_value' and 'answer_format'.
// To bypass this, we pull the values out of this array and force
// them to be saved in 'answer' and 'answer_format'.
$values['answer_format'] = $values['answer']['format'];
$values['answer'] = $values['answer']['value'];
}
// Here we test if the values are default ones, yes? -> remove them.
if (isset($instance['default_values'])) {
if ($values['question'] == $instance['default_values']['question']) {
if ($values['answer'] == $instance['default_values']['answer']) {
unset($items[$key]);
}
}
}
}
}