1

I've added a tab adjacent to the event "Info and Settings" configuration tab, using hook_civicrm_tabset(), but when I link to the URL for that tab, the "Info and Settings" tab is displayed. This behavior is different from that of native tabs, such as "Location": I can type in the URL for that tab, and the tab is correctly selected.

Question: How can I get my "My Settings" tab to display itself from a URL in a way that's equivalent to the behavior of native tabs such as Location?


Here are some examples of native URLs that work as expected, and my custom tab which does not.

"Info and Settings" tab
http://example.l/civicrm/event/manage/settings?reset=1&action=update&id=23

enter image description here


"Location" tab
http://example.l/civicrm/event/manage/location?reset=1&action=update&id=23

enter image description here


"My Settings" tab
http://example.l/civicrm/event/manage/mysettings?reset=1&action=update&id=23

enter image description here


Example code (slightly redacted for public viewing)

/**
 * Implements hook_civicrm_tabset().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tabset/
 */
function myextension_civicrm_tabset($tabsetName, &$tabs, $context) {
  if ($tabsetName == 'civicrm/event/manage') {
    if ($eventId = CRM_Utils_Array::value('event_id', $context)) {
      $tab['mysettings'] = array(
        'title' => E::ts('My Settings'),
        'link' => NULL, // 'link' is automatically provided if we're under the 'civicrm/event/manage' path.
        'class' => 'ajaxForm', // allows form to re-load itself on save.
        'valid' => _myextension_EventHasMySettings($eventId), // indicates whether tab has actively used settings.
        'active' => TRUE,
        'current' => FALSE, // setting this to FALSE prevents the tab from pre-loading
                            // focus when the page is loaded.
      );
    }
    else {
      $tab['mysettings'] = array(
        'title' => E::ts('My Settings'),
        'url' => 'civicrm/event/manage/mysettings',
        'field' => 'is_my_settings',
      );
    }
    //Insert this tab into position 1
    $tabs = array_merge(
      array_slice($tabs, 0, 1),
      $tab,
      array_slice($tabs, 1)
    );
  }

  // Set mysettings tab as enabled/disabled in configuration popup-menu, on manage events listing screen.
  if ($tabsetName == 'civicrm/event/manage/rows' && $eventId = CRM_Utils_Array::value('event_id', $context)) {
    $tabs[$eventId]['is_my_settings'] = _myextension_EventHasMySettings($eventId);
  }
}


2

You will need to add below line in your preprocess() function.

$this->assign('selectedChild', 'mysettings');
| improve this answer | |
  • I don't have a preprocess hook implementation at this point. But I added that assign() statement to the buildQuickForm() method of my CRM_Myextension_Form_Event_Mysettings() form class (the class that's mapped to this tab URL in the menu xml), and that does the trick. I'm guessing that's essentially what you meant. Thanks! – TwoMice Mar 12 at 16:20
  • Sorry i meant function not hook, it can either go in preprocess or buildquickform function of your form class. – Pradeep Nayak Mar 12 at 16:22
  • So are you happy to mark this is as answered? – Pradeep Nayak Mar 12 at 16:23
  • With the edit, yes. Thanks! – TwoMice Mar 12 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.