protected function AvailabilityCalendarFieldHandler::prepareCalendar in Availability Calendars 7.5
Prepares an Availability Calendar.
The actual availability data is not stored in field storage but in tables specific to the module. Therefore we have to prepare a calendar field by first storing the availability data in those module owned tables and then storing the reference to that data, the cid (= calendar ID), in the field.
Parameters
string|array[] $dates: Availability data, either in a string format, see README.txt, or in an array as accepted by availability_calendar_update_multiple_availability().
array $element: Field configuration expected by availability_calendar_field_widget_month_form_validate_line().
object $entity: Entity about to be created by Migrate.
Return value
int ID of the newly created availability calendar entity.
1 call to AvailabilityCalendarFieldHandler::prepareCalendar()
- AvailabilityCalendarFieldHandler::prepare in ./
availability_calendar_migrate_field_handlers.inc - Prepares data accordingly for the field API.
File
- ./
availability_calendar_migrate_field_handlers.inc, line 96 - Migrate field handlers.
Class
- AvailabilityCalendarFieldHandler
- Migrates availability data to availability_calendar fields.
Code
protected function prepareCalendar($dates, $element, $entity) {
if (!$dates) {
return NULL;
}
if (is_string($dates)) {
$dates = $this
->convertAvailabilityString($dates, $element);
}
$field_name = $element['#field_name'];
$language_code = $element['#language'];
$delta = $element['#delta'];
// Update or create calendar.
$cid = isset($entity->{$field_name}[$language_code][$delta]['cid']) ? $entity->{$field_name}[$language_code][$delta]['cid'] : NULL;
$cid = availability_calendar_update_multiple_availability($cid, $dates);
if (!isset($entity->{$field_name}[$language_code][$delta]['cid']) || $cid != $entity->{$field_name}[$language_code][$delta]['cid']) {
// New calendar: update field.
$entity->{$field_name}[$language_code][$delta]['cid'] = $cid;
}
return $cid;
}