SMF Development > Applied or Declined Requests

Integration hook in order to add options and settings to themes

(1/2) > >>

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

--- End code ---

but an integration hook will be usefull:

--- Code: (Themes/default/Settings.template.php) ---<?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']));
}

?>
--- End code ---

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.

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.

--- End quote ---
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.

--- End quote ---
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) ---<?php

loadTemplate('Settings');
loadSubTemplate('options');
// New hook.
call_integration_hook('integrate_theme_options');
?>
--- End code ---

--- Code: (Sources/Themes.php, line 683) ---<?php

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

?>
--- End code ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version