function date_repeat_entity_update_dates in Date Repeat Entity 7.2
Same name and namespace in other branches
- 7 includes/date_repeat_entity.update.inc \date_repeat_entity_update_dates()
Update or replaces date entities based on a scope determined by user.
Parameters
object $entity: The entity being updated.
string $entity_type: the entity type to load
1 call to date_repeat_entity_update_dates()
- date_repeat_entity_entity_presave in ./
date_repeat_entity.module - Implements hook_entity_presave().
File
- includes/
date_repeat_entity.update.inc, line 18 - Contains functions that support update of entities with repeating date fields.
Code
function date_repeat_entity_update_dates($entity, $entity_type) {
// Get entity wrapper.
$entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
$bundle = $entity_wrapper
->getBundle();
// Get value of clone state - a new entity will have the default state
// of FALSE while a cloned entity will have a state of TRUE.
$field_clone_state_value = $entity_wrapper->{DATE_REPEAT_ENTITY_FIELD_CLONE_STATE}
->value();
// Only act on entities that are not clones or equivalent.
if ($field_clone_state_value === FALSE) {
$scope = $entity->date_repeat_entity['scope'];
// Determine if there is has been a material change between the
// original and updated entity.
$repeating_date_has_changed = module_invoke_all('repeating_date_has_changed', $entity->original, $entity, $entity_type);
// If the repeating date pattern has changed then replace the entities.
if (in_array(TRUE, $repeating_date_has_changed)) {
// Replace dates and update entity with new master uuid and related
// properties.
$entity = _date_repeat_entity_replace_dates($entity, $entity_type, $bundle, $scope);
}
else {
// Update dates, keeping same master uuid.
_date_repeat_entity_update_dates($entity_wrapper, $entity, $entity_type, $bundle, $scope);
}
}
// Find out which field we are operating on.
$repeating_date_field = date_repeat_entity_get_repeating_date_field($entity_type, $bundle);
$repeating_date_field_name = $repeating_date_field['field_name'];
$repeating_date_field_language = field_language($entity_type, $entity, $repeating_date_field_name);
// Remove any date field delta values that were created during the save
// operation - any existing entities should not have these deltas.
array_splice($entity->{$repeating_date_field_name}[$repeating_date_field_language], 1);
// Make sure entity clone state is set to FALSE - this should be normal state.
$entity_wrapper->{DATE_REPEAT_ENTITY_FIELD_CLONE_STATE} = FALSE;
}