I was experimenting with hook_menu in a theme. It doesn't seem to work. 

I found this page listing theme functions. It is safe to say that if hook_menu is not listed here, it's not available to themes?

https://docs.backdropcms.org/api/backdrop/theme-functions (edited)

Is this a safe guide to what themes can do with code or is it more complicated than this?

Context:

I was interested in creating a second page of configuration options for Tatsu theme, to resolve this issue: https://github.com/backdrop-contrib/tatsu/issues/72

Is it possible to create a second page or second tab of settings for a theme?

Suggestions?

Comments

@stpaultim

I found this page listing theme functions. It is safe to say that if hook_menu is not listed here, it's not available to themes?

Which page?

Thanks for posting. That listing is showing the theming functions provided by core. hook_menu is not a theming function - it's a hook. It should work in your template.php. If you could post some of the code you are using, that would make it easier to catch the problem.

Could you post an example of how you are trying to use hook_menu in that theme? Inside template.php?

OK, I originally tried this in theme-settings.php, but have also tried it in template.php. It works in neither. 

I was able to get this code to work inside a custom module. 

  function tatsu_menu() {
    $items['custom-forms'] = array(
      'title' => 'Custom Form',
      'page callback' => array('custom_form_test'),
      'access callback' => TRUE,
      'expanded' => TRUE,
    );
    return $items;
  }

  function custom_form_test() {
    return array(
      '#markup' => '<p>' . t('The quick brown fox jumps over the lazy dog.') . '</p>',
    );
  }

When I say it does not work, I mean that this path generates a page not found error.

/custom-forms

Great! Yes, this looks fine. The 'expanded' option doesn't work unless you put this in a menu by using menu_name.

And to control access you can use 'access arguments' => array('administer themes'), for example, and leave out 'access callback'.

Oops, read too fast. So it doesn't work in template.php... hmmm. I've never tried that so I guess it doesn't work there.

So the next question is whether or not there is a way to create a custom form on a page OTHER than the main settings page in a theme?

EDIT: This was discussed with several core developers who seem to agree that my interest in creating a second configuration form for my theme is not possible at this time. I hope to make a feature request to core that will address this.