function availability_calendar_i18n_sync_availability_calendar_field in Availability Calendars 7.3
Same name and namespace in other branches
- 7.5 availability_calendar.module \availability_calendar_i18n_sync_availability_calendar_field()
- 7.4 availability_calendar.module \availability_calendar_i18n_sync_availability_calendar_field()
Callback to sync a calendar field:
- Calendar-id (cid) is synced.
- Enabled is synced.
- Order of cid's is synced.
- Name is kept if already existing, copied otherwise.
Parameters
string $entity_type:
object $entity: The target entity.
array $field: field_info_field() info array.
array $instance: field_info_instance() info array.
string $langcode: Target language code.
array $items: The items to sync. in: source langauge items; out: target language items
object $source_entity: The source entity.
string $source_language: The source language code
1 string reference to 'availability_calendar_i18n_sync_availability_calendar_field'
File
- ./
availability_calendar.module, line 336 - Availability Calendar module. Defines an availability calendar as a field.
Code
function availability_calendar_i18n_sync_availability_calendar_field($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_language) {
$field_name = $instance['field_name'];
// Build a copy of the existing calendars in the translation node indexed by
// cid for easy retrieval in the copy loop below.
$existing_items = field_get_items($entity_type, $entity, $instance['field_name'], $langcode);
$existing_calendars = array();
if ($existing_items !== FALSE) {
foreach ($existing_items as $delta => $calendar) {
$existing_calendars[$calendar['cid']] = $calendar;
}
}
// Start creating the translated copy.
$property = 'name';
foreach ($items as $delta => &$calendar) {
// keep name if it already exists.
if (array_key_exists($calendar['cid'], $existing_calendars)) {
if (!empty($existing_calendars[$calendar['cid']][$property])) {
$calendar[$property] = $existing_calendars[$calendar['cid']][$property];
}
}
}
}