You are here

function menu_link_field_attach_prepare_translation_alter in Menu Link (Field) 7

Implements hook_field_attach_prepare_translation_alter().

For newly created translations, enforces empty menu link fields.

Otherwise menu_link would set the language of the menu item back and forth upon editing one and the other translated entity.

File

./menu_link.module, line 313

Code

function menu_link_field_attach_prepare_translation_alter($entity, $context) {
  list(, , $bundle) = entity_extract_ids($context['entity_type'], $entity);
  foreach (field_info_instances($context['entity_type'], $bundle) as $instance) {
    $field_name = $instance['field_name'];
    $field = field_info_field($field_name);
    if ($field['module'] == 'menu_link') {
      if (isset($entity->{$field_name}) && !empty($entity->{$field_name})) {
        $entity->{$field_name} = array();
      }
    }
  }
}