function calendar_systems_date_properties_entity_presave in Calendar Systems 8
Same name and namespace in other branches
- 7 calendar_systems_date_properties/calendar_systems_date_properties.module \calendar_systems_date_properties_entity_presave()
- 7.2 calendar_systems_date_properties/calendar_systems_date_properties.module \calendar_systems_date_properties_entity_presave()
hook_entity_presave
Parameters
$entity:
$type:
File
- calendar_systems_date_properties/
calendar_systems_date_properties.module, line 66 - Contains hook implementations and helpers.
Code
function calendar_systems_date_properties_entity_presave($entity, $type) {
$entity_types = _calendar_systems_date_properties_entity_types();
$entity_type_info = @$entity_types[$type];
if (isset($entity_type_info['integrated']) && $entity_type_info['integrated']) {
$calendar_systems = _calendar_systems_date_properties_get_active_calendar_systems();
foreach ($entity_type_info['selected_properties'] as $property_name => $property) {
foreach ($calendar_systems as $calendar_system) {
$calendar = calendar_systems_get_calendar_instance($calendar_system['name']);
$time = $entity->{$property_name};
if ($time > 0) {
$date = $calendar
->timestampToInfoArray($time);
foreach ($calendar_system['parts'] as $calendar_system_part_name => $calendar_system_part) {
$new_property_name = $property_name . '_' . $calendar_system['name'] . '_' . $calendar_system_part_name;
$entity->{$new_property_name} = $date[$calendar_system_part_name];
}
}
}
}
}
}