/**
 * Inform modules that a menu link has been created.
 *
 * This hook is used to notify modules that menu items have been
 * created. Contributed modules may use the information to perform
 * actions based on the information entered into the menu system.
 *
 * @param $link
 *   Associative array defining a menu link as passed into menu_link_save().
 *
 * @see hook_menu_link_update()
 * @see hook_menu_link_delete()
 */
function hook_menu_link_insert($link)
{
    // In our sample case, we track menu items as editing sections
    // of the site. These are stored in our table as 'disabled' items.
    $record['mlid'] = $link['mlid'];
    $record['menu_name'] = $link['menu_name'];
    $record['status'] = 0;
    backdrop_write_record('menu_example', $record);
}
/**
 * Act before entity deletion.
 *
 * This hook runs after the entity type-specific predelete hook.
 *
 * @param $entity
 *   The entity object for the entity that is about to be deleted.
 * @param $type
 *   The type of entity being deleted (e.g. node, user, comment).
 */
function hook_entity_predelete($entity, $type)
{
    // Count references to this entity in a custom table before they are removed
    // upon entity deletion.
    list($id) = entity_extract_ids($type, $entity);
    $count = db_select('example_entity_data')->condition('type', $type)->condition('id', $id)->countQuery()->execute()->fetchField();
    // Log the count in a table that records this statistic for deleted entities.
    $ref_count_record = (object) array('count' => $count, 'type' => $type, 'id' => $id);
    backdrop_write_record('example_deleted_entity_statistics', $ref_count_record);
}