Advertisement:

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

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 971
  • 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

  • Developer
  • SMF Super Hero
  • *
  • Posts: 15,290
  • Kaizoku Jotei
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.

Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 971
  • 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: 68,732
    • Arantor on GitHub
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 971
  • 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: 68,732
    • Arantor on GitHub
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 971
  • 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: 68,732
    • Arantor on GitHub
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Offline Sesquipedalian

  • Lead Developer
  • Jr. Member
  • *
  • Posts: 317
  • Gender: Male
  • It works! ... in theory.
    • Sesquipedalian on GitHub
I promise you nothing.

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