Example #1
0
/**
 * Implementation of hook_civicrm_tabset
 *
 * Insert the "Volunteer" tab into the event edit workflow
 */
function volunteer_civicrm_tabset($tabsetName, &$tabs, $context)
{
    if ($tabsetName == 'civicrm/event/manage') {
        if (!empty($context)) {
            $eventID = $context['event_id'];
            $url = CRM_Utils_System::url('civicrm/event/manage/volunteer', "reset=1&snippet=5&force=1&id={$eventID}&action=update&component=event");
            $tab['volunteer'] = array('title' => ts('Volunteers', array('domain' => 'org.civicrm.volunteer')), 'link' => $url, 'valid' => TRUE, 'active' => TRUE, 'class' => 'livePage', 'current' => false);
            // If volunteer mngmt is enabled, add necessary UI elements
            if (CRM_Volunteer_BAO_Project::isActive($eventID, CRM_Event_DAO_Event::$_tableName)) {
                CRM_Volunteer_Form_Manage::addResources($eventID, CRM_Event_DAO_Event::$_tableName);
            } else {
                $tab['volunteer']['valid'] = FALSE;
            }
        } else {
            $tab['volunteer'] = array('title' => ts('Volunteers', array('domain' => 'org.civicrm.volunteer')), 'url' => 'civicrm/event/manage/volunteer', 'field' => 'is_volunteer');
        }
        // Insert this tab into position 4
        $tabs = array_merge(array_slice($tabs, 0, 4), $tab, array_slice($tabs, 4));
    }
    // on manage events listing screen, this section sets volunteer tab in configuration popup as enabled/disabled.
    if ($tabsetName == 'civicrm/event/manage/rows' && CRM_Utils_Array::value('event_id', $context)) {
        $eventID = $context['event_id'];
        $tabs[$eventID]['is_volunteer'] = CRM_Volunteer_BAO_Project::isActive($eventID, CRM_Event_DAO_Event::$_tableName);
    }
}