function _biblio_truncate_long_fields in Bibliography Module 7.2
Truncates field values that are longer than the specified field value length. This is particularly useful when importing biblio entities.
Parameters
object $entity:
string $type:
1 call to _biblio_truncate_long_fields()
- biblio_entity_presave in ./
biblio.module - Implements hook_entity_presave().
File
- ./
biblio.module, line 3799
Code
function _biblio_truncate_long_fields($entity, $type) {
$valid_entity_types = array(
'biblio',
'biblio_contributor',
);
if (!in_array($type, $valid_entity_types)) {
return;
}
$wrapper = biblio_wrapper($entity, $type);
$entity_info = entity_get_info($type);
$fields_info = field_info_fields();
foreach ($entity as $field => $field_structure) {
if (isset($fields_info[$field]) && ($value = $wrapper->{$field}
->value())) {
$field_settings = $fields_info[$field]['settings'];
if (is_string($value) && isset($field_settings['max_length'])) {
$max_length = $field_settings['max_length'];
$length = strlen($value);
if ($length > $max_length) {
$wrapper->{$field} = substr($value, 0, $max_length);
}
}
}
}
}