You are here

function _date_repeat_entity_replace_dates in Date Repeat Entity 7

Same name and namespace in other branches
  1. 7.2 includes/date_repeat_entity.update.inc \_date_repeat_entity_replace_dates()

Replace dates associated with a repeating date series.

Parameters

object $entity: The entity being updated.

string $entity_type: The entity type to load, e.g. node.

string $bundle: The bundle type, e.g. event.

string $scope: Defines the extent to which date series should be searched. Can be one of: current (for the current date instance only), future (for the current and all future date instances), all (all instances of a date series).

Return value

object Represents the entity that has been updated with a new uuid.

1 call to _date_repeat_entity_replace_dates()
date_repeat_entity_update_dates in includes/date_repeat_entity.update.inc
Update or replaces date entities based on a scope determined by user.

File

includes/date_repeat_entity.update.inc, line 82
Contains functions that support update of entities with repeating date fields.

Code

function _date_repeat_entity_replace_dates($entity, $entity_type, $bundle, $scope = 'current') {

  // Clone the entity before the UUID gets changed.
  // Notes:
  // - use the clone method rather than replicate_clone_entity which resets
  //   the entity_id.
  // - cannot clone the original wrapper because it still points to the original
  //   entity.
  // - clone the entity's original state as stored in entity->original.  This
  //   is because we need to use the original start date when the scope is
  //   'future'.
  $original_entity = clone $entity->original;
  $original_entity_wrapper = entity_metadata_wrapper($entity_type, $original_entity);

  // Generate a new master UUID.
  $master_uuid_new = uuid_generate();

  // Change the entity uuid and set its status to new.
  $entity->uuid = $master_uuid_new;
  $entity->vuuid = $master_uuid_new;

  // Create new dates based on the current entity and RRULE defined with it.
  date_repeat_entity_create_dates($entity, $entity_type);

  // Make sure repeating date delete functions are available.
  module_load_include('inc', 'date_repeat_entity', 'includes/date_repeat_entity.delete');

  // Delete original date entities that were replaced
  // - excluding the current entity date because it will be updated by the save
  // action that called this function.
  $exclude_current_entity = TRUE;
  date_repeat_entity_delete_dates($original_entity_wrapper, $entity_type, $bundle, $scope, $exclude_current_entity);
  return $entity;
}