function menu_link_field_insert in Menu Link (Field) 7
Implements hook_field_insert().
File
- ./
menu_link.field.inc, line 197 - Defines a menu link field type.
Code
function menu_link_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
$path = _menu_link_path($entity_type, $entity, $langcode);
foreach ($items as $delta => &$item) {
if (empty($field['settings']['link_path_field']) || empty($item['link_path'])) {
$item['link_path'] = $path;
}
// If the options array was serialized on a previous insert or update,
// unserialize it back to an array for menu_link_save().
if (isset($item['options']) && is_string($item['options'])) {
$item['options'] = unserialize($item['options']);
}
if (!menu_link_save($item)) {
drupal_set_message(t('There was an error saving the menu link.'), 'error');
}
else {
// Workaround, menu_link_save during entity creation process
// can lead to incomplete cache entries, let's discard those.
$cid = "field:{$entity_type}:{$entity->id}";
cache_clear_all($cid, 'cache_field');
}
$item['options'] = serialize($item['options']);
}
}