You are here

function availability_calendar_i18n_sync_availability_calendar_field in Availability Calendars 7.4

Same name and namespace in other branches
  1. 7.5 availability_calendar.module \availability_calendar_i18n_sync_availability_calendar_field()
  2. 7.3 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 language 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'
availability_calendar_field_info in ./availability_calendar.field.inc
Implements hook_field_info(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

File

./availability_calendar.module, line 348

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 $calendar) {
      $existing_calendars[$calendar['cid']] = $calendar;
    }
  }

  // Start creating the translated copy.
  $property = 'name';
  foreach ($items as &$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];
      }
    }
  }
}