You are here

public function AvailabilityCalendarFieldHandler::prepare in Availability Calendars 7.5

Prepares data accordingly for the field API.

Parameters

object $entity: Entity about to be created by Migrate.

array $field_info: A field data structure.

array $instance: A field instance structure.

array $values: An array of availability values to migrate. Each value is either a string or availability values or an array of availability changes where each entry is an array with keys state, from and to.

Return value

array|null The field value. Note that this value is only a reference to an availability calendar and that as a side effect, that calendar will have been updated based on the $values.

File

./availability_calendar_migrate_field_handlers.inc, line 40
Migrate field handlers.

Class

AvailabilityCalendarFieldHandler
Migrates availability data to availability_calendar fields.

Code

public function prepare($entity, array $field_info, array $instance, array $values) {
  module_load_include('inc', 'availability_calendar', 'availability_calendar.widget');
  $arguments = isset($values['arguments']) ? $values['arguments'] : array();
  $language = $this
    ->getFieldLanguage($entity, $field_info, $arguments);
  $delta = 0;
  $return = array();

  // In order to be compatible with the way Availability Calendars works, see
  // prepareCalendar() method.
  $element = array(
    'availability_states' => array(
      '#options' => availability_calendar_get_states(),
    ),
    'availability_calendar' => array(
      '#settings' => $instance['widget']['settings'],
    ),
    '#field_name' => $instance['field_name'],
    '#language' => $language,
  );
  foreach ($values as $value) {
    $element['#delta'] = $delta;
    $cid = $this
      ->prepareCalendar($value, $element, $entity);
    if (!$cid) {
      return NULL;
    }
    $return[$language][$delta] = array(
      'enabled' => 1,
      'name' => '',
      'cid' => $cid,
    );
    $delta++;
  }
  return $return;
}