You are here

function groupmenu_entity_insert in Group Menu 7

Implements hook_entity_insert().

File

./groupmenu.module, line 381
Integrates menu with Group.

Code

function groupmenu_entity_insert($entity, $type) {
  if ($type != 'group') {
    return;
  }

  /** @var Group $entity */
  if (variable_get('groupmenu_create_by_default', FALSE)) {
    $menu_name = 'menu-group-' . $entity->gid;
    menu_save(array(
      'menu_name' => $menu_name,
      'title' => $entity->title,
      'description' => t('Group Menu for @title', array(
        '@title' => $entity->title,
      )),
    ));
    groupmenu_update_menu('menu-group-' . $entity->gid, $entity->gid);

    // Also create an initial menu entry for the new group.
    $item = array(
      'link_path' => drupal_get_normal_path('group/' . $entity->gid),
      'link_title' => $entity->title,
      'menu_name' => $menu_name,
    );
    menu_link_save($item);
  }
  groupmenu_group_save($entity);
}