Simple Machines Community Forum

SMF Development => Feature Requests => Applied or Declined Requests => Topic started by: davidhs on December 21, 2017, 08:44:44 AM

Title: Integration hook in order to add options and settings to themes
Post by: davidhs 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']));
}

?>
Title: Re: Integration hook in order to add options and settings to themes
Post by: Suki 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.
Title: Re: Integration hook in order to add options and settings to themes
Post by: davidhs on December 21, 2017, 12:21:22 PM
Quote from: Suki 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.
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).
Title: Re: Integration hook in order to add options and settings to themes
Post by: Arantor 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.
Title: Re: Integration hook in order to add options and settings to themes
Post by: davidhs on December 21, 2017, 12:54:30 PM
Quote from: Arantor 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.
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.
Title: Re: Integration hook in order to add options and settings to themes
Post by: Arantor on December 21, 2017, 01:42:30 PM
It's not the theme's responsibility to make this work.
Title: Re: Integration hook in order to add options and settings to themes
Post by: davidhs on December 21, 2017, 01:58:30 PM
Quote from: Arantor on December 21, 2017, 01:42: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
Title: Re: Integration hook in order to add options and settings to themes
Post by: Arantor on December 21, 2017, 02:09:18 PM
Yup, especially as it's not likely to be called in any other places in practice.
Title: Re: Integration hook in order to add options and settings to themes
Post by: Sesquipedalian on February 13, 2018, 11:57:08 PM
https://github.com/SimpleMachines/SMF2.1/pull/4546