Advertisement:

Author Topic: Integration hook in order to add options and settings to themes  (Read 53071 times)

Offline davidhs

  • Sophist Member
  • *****
  • Posts: 1,107
  • Gender: Male
Integration hook in order to add options and settings to themes
« on: December 21, 2017, 08:44:44 AM »
I searched in GitHub and I do not found this...

Is there an integration hook in order to add settings to themes? Now I can do this:
Code: (modification.xml) [Select]
<file name="$themedir/Settings.template.php">
<operation>
<search position="before"><![CDATA[
2 => $txt['who_display_viewing_names'],
),
'type' => 'number',
),
]]></search>
<add><![CDATA[
array(
'id' => 'my_theme_setting',
'label' => $txt['my_theme_setting'],
'description' => $txt['my_theme_setting_desc'],
'type' => 'text',
),
]]></add>
</operation>
</file>

but an integration hook will be usefull:
Code: (Themes/default/Settings.template.php) [Select]
<?php

function template_options()
{
$context['theme_options'] = array(
// Options.
);
call_integration_hook('integrate_theme_options', array(&$context['theme_options']));
}

function 
template_settings()
{
$context['theme_settings'] = array(
// Settings.
);
call_integration_hook('integrate_theme_settings', array(&$context['theme_settings']));
}

?>

Offline Suki

  • Carthago delenda est
  • Lead Developer
  • SMF Super Hero
  • *
  • Posts: 15,806
  • Oh, wouldn't it be great if I *was* crazy?
    • MissAllSunday on GitHub
    • SMF mods
Re: Integration hook in order to add options and settings to themes
« Reply #1 on: December 21, 2017, 09:37:24 AM »
Don't have a copy to verify but there should be a hook called after those functions have been called.

Since its a $context key you don't really need to pass it as an argument, you can call your function with a hook, globalize $context and manipulate it whatever you prefer.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Making tough decisions, so you don't have to.

Offline davidhs

  • Sophist Member
  • *****
  • Posts: 1,107
  • Gender: Male
Re: Integration hook in order to add options and settings to themes
« Reply #2 on: December 21, 2017, 12:21:22 PM »
Don't have a copy to verify but there should be a hook called after those functions have been called.
There is not a hook called after call those functions (in Sources/Profile-Modify.php, line 1815, and Sources/Themes.php, lines 559 and 683).

In any case, I think hook must be indoor those functions (not after be called).

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 72,951
Re: Integration hook in order to add options and settings to themes
« Reply #3 on: December 21, 2017, 12:23:44 PM »
Given that it's a global var, it can easily be after those functions are called, rather than trying to fit them into the theme itself.

Offline davidhs

  • Sophist Member
  • *****
  • Posts: 1,107
  • Gender: Male
Re: Integration hook in order to add options and settings to themes
« Reply #4 on: December 21, 2017, 12:54:30 PM »
Given that it's a global var, it can easily be after those functions are called, rather than trying to fit them into the theme itself.
Yes, but in this case the hook should be called after any call of these functions. For example:
Code: (Sources/Profile-Modify.php, line 1815; Sources/Themes.php, line 559) [Select]
<?php

loadTemplate('Settings');
loadSubTemplate('options');
// New hook.
call_integration_hook('integrate_theme_options');
?>
Code: (Sources/Themes.php, line 683) [Select]
<?php

loadTemplate('Settings');
loadSubTemplate('settings');
// New hook.
call_integration_hook('integrate_theme_settings');

?>

Now are called only in three lines, but they can be called more times.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 72,951
Re: Integration hook in order to add options and settings to themes
« Reply #5 on: December 21, 2017, 01:42:30 PM »
It's not the theme's responsibility to make this work.

Offline davidhs

  • Sophist Member
  • *****
  • Posts: 1,107
  • Gender: Male
Re: Integration hook in order to add options and settings to themes
« Reply #6 on: December 21, 2017, 01:58:30 PM »
It's not the theme's responsibility to make this work.
Ok, then is better use the hook after call functions, like my last example https://www.simplemachines.org/community/index.php?topic=557846.msg3953192#msg3953192

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 72,951
Re: Integration hook in order to add options and settings to themes
« Reply #7 on: December 21, 2017, 02:09:18 PM »
Yup, especially as it's not likely to be called in any other places in practice.

Offline Sesquipedalian

  • The Mad Doctor
  • Developer
  • Sophist Member
  • *
  • Posts: 1,129
  • Gender: Male
  • It works! ... in theory.
    • Sesquipedalian on GitHub
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.