function date_repeat_entity_entity_presave in Date Repeat Entity 7
Same name and namespace in other branches
- 7.2 date_repeat_entity.module \date_repeat_entity_entity_presave()
Implements hook_entity_presave().
When a new entity is created we need this hook because it is called after the entity object is created but before it is saved to the database.
File
- ./
date_repeat_entity.module, line 399 - Adds functionality to entities with repeating date fields
Code
function date_repeat_entity_entity_presave($entity, $entity_type) {
// Make sure utility functions are available.
module_load_include('inc', 'date_repeat_entity', 'includes/date_repeat_entity.utility');
// Make sure repeating date create functions are available.
module_load_include('inc', 'date_repeat_entity', 'includes/date_repeat_entity.create');
// Make sure repeating date update functions are available.
module_load_include('inc', 'date_repeat_entity', 'includes/date_repeat_entity.update');
// Get entity wrapper.
$wrapper = entity_metadata_wrapper($entity_type, $entity);
// Get bundle type.
$bundle = $wrapper
->getBundle();
// Check if the entity attached to the form has a repeating date field.
$repeating_date_field = date_repeat_entity_get_repeating_date_field($entity_type, $bundle);
// Check if the entity also has other fields required for this module to
// function properly.
$master_uuid_field = date_repeat_entity_get_field($entity_type, $bundle, DATE_REPEAT_ENTITY_FIELD_MASTER_UUID);
$clone_state_field = date_repeat_entity_get_field($entity_type, $bundle, DATE_REPEAT_ENTITY_FIELD_CLONE_STATE);
if ($repeating_date_field != NULL && $master_uuid_field != NULL && $clone_state_field != NULL) {
if ($entity->is_new) {
date_repeat_entity_create_dates($entity, $entity_type);
}
else {
date_repeat_entity_update_dates($entity, $entity_type);
}
}
}