Answers.Body: <p>You will need to add below line in your preprocess() function.</p>
  
  <pre><code>$this-&gt;assign('selectedChild', 'mysettings');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T16:20:07.197Z
Answers.Text: 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!
Answers.UserDisplayName: TwoMice
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T16:22:53.730Z
Answers.Text: Sorry i meant function not hook, it can either go in preprocess or buildquickform function of your form class.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T16:23:43.947Z
Answers.Text: So are you happy to mark this is as answered?
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T16:25:39.147Z
Answers.Text: With the edit, yes. Thanks!
Answers.UserDisplayName: TwoMice
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T16:01:31.097Z
Answers.LastActivityDate: 2020-03-12T16:22:24.863Z
Answers.LastEditDate: 2020-03-12T16:22:24.863Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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.</p>
  
  <p><strong>Question:</strong> 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?</p>
  
  <hr>
  
  <p>Here are some examples of native URLs that work as expected, and my custom tab which does not.</p>
  
  <p><strong>"Info and Settings" tab</strong><br>
  <a href="http://example.l/civicrm/event/manage/settings?reset=1&amp;action=update&amp;id=23" rel="nofollow noreferrer">http://example.l/civicrm/event/manage/settings?reset=1&amp;action=update&amp;id=23</a></p>
  
  <p><a href="https://i.sstatic.net/dwQVx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dwQVx.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>"Location" tab</strong><br>
  <a href="http://example.l/civicrm/event/manage/location?reset=1&amp;action=update&amp;id=23" rel="nofollow noreferrer">http://example.l/civicrm/event/manage/location?reset=1&amp;action=update&amp;id=23</a></p>
  
  <p><a href="https://i.sstatic.net/jNo7i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jNo7i.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>"My Settings" tab</strong><br>
  <a href="http://example.l/civicrm/event/manage/mysettings?reset=1&amp;action=update&amp;id=23" rel="nofollow noreferrer">http://example.l/civicrm/event/manage/mysettings?reset=1&amp;action=update&amp;id=23</a></p>
  
  <p><a href="https://i.sstatic.net/dwQVx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dwQVx.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p>Example code (slightly redacted for public viewing)</p>
  
  
  
  <pre><code>/**
   * Implements hook_civicrm_tabset().
   *
   * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tabset/
   */
  function myextension_civicrm_tabset($tabsetName, &amp;$tabs, $context) {
    if ($tabsetName == 'civicrm/event/manage') {
      if ($eventId = CRM_Utils_Array::value('event_id', $context)) {
        $tab['mysettings'] = array(
          'title' =&gt; E::ts('My Settings'),
          'link' =&gt; NULL, // 'link' is automatically provided if we're under the 'civicrm/event/manage' path.
          'class' =&gt; 'ajaxForm', // allows form to re-load itself on save.
          'valid' =&gt; _myextension_EventHasMySettings($eventId), // indicates whether tab has actively used settings.
          'active' =&gt; TRUE,
          'current' =&gt; FALSE, // setting this to FALSE prevents the tab from pre-loading
                              // focus when the page is loaded.
        );
      }
      else {
        $tab['mysettings'] = array(
          'title' =&gt; E::ts('My Settings'),
          'url' =&gt; 'civicrm/event/manage/mysettings',
          'field' =&gt; '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' &amp;&amp; $eventId = CRM_Utils_Array::value('event_id', $context)) {
      $tabs[$eventId]['is_my_settings'] = _myextension_EventHasMySettings($eventId);
    }
  }
  
  
  </code></pre>
  
Tags: <extension><hooks>
Title: Using hook_civicrm_tabset; why doesn't my tab focus when linked to via url?
ThreadText: # Using hook_civicrm_tabset; why doesn't my tab focus when linked to via url?
  
  (Asked by: username_0 on 2020-03-12)
  
  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
  
  
  "Location" tab
  http://example.l/civicrm/event/manage/location?reset=1&action=update&id=23
  
  
  "My Settings" tab
  http://example.l/civicrm/event/manage/mysettings?reset=1&action=update&id=23
  
  
  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);
    }
  }
  
  **Tags:** extension, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-12. Score: 1 | Accepted answer
  
  You will need to add below line in your preprocess() function.
  $this->assign('selectedChild', 'mysettings');
  
  > **Comments:**
  > **username_0**: 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!  
  > **username_1**: Sorry i meant function not hook, it can either go in preprocess or buildquickform function of your form class.  
  > **username_1**: So are you happy to mark this is as answered?  
  > **username_0**: With the edit, yes. Thanks!  
  
  ---
  
  