News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Integration hook in order to add options and settings to themes

Started by davidhs, December 21, 2017, 08:44:44 AM

Previous topic - Next topic

davidhs

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']));
}

?>

Suki

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.

davidhs

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).

Arantor

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.

davidhs

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.

Arantor



Arantor

Yup, especially as it's not likely to be called in any other places in practice.

Sesquipedalian

I promise you nothing.

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

Advertisement: