News:

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

Main Menu

Mod hooks question/problem...

Started by Kindred, December 16, 2020, 04:39:33 PM

Previous topic - Next topic

Kindred

So, I'm working on updating the glossary mod so that is entirely hook based.
I could go back and do the edit to the ManageSettings file, but I'd rather do hooked, because it makes upgrades a hell of a lot easier...

I need to add a subsection to the admin > configuration > modification settings screen with it's own tab...

I have the following hooks used:
$hook_functions = array(
    'integrate_pre_include' => '$sourcedir/GlossaryHooks.php',
    'integrate_admin_areas' => 'glossary_admin',
    'integrate_modify_modifications' => 'glossary_settings',
    'integrate_bbc_codes' => 'glossary_bbcode',
    'integrate_bbc_buttons' => 'glossary_bbcode_button',
    'integrate_pre_parsebbc' => 'parse_glossary',
    'integrate_menu_buttons' => 'glossary_menu_buttons',
    'integrate_actions' => 'glossary_actions',
    'integrate_load_permissions' => 'glossary_load_permissions',
    'integrate_load_theme' => 'glossary_load_theme',
);


First line calls the hooks code file...
Second line sets the mod button and it appears in the section as expected
Third line is where it's beaking down for me.

When I got INTO the admin section, there is no content and the I get a bunch of errors in the errorlog regarding bad foreach, etc

here's my hooked code.

Any ideas what I did wrong?

// Hook for Admin options
function glossary_admin(&$admin_areas)
{
global $txt;

$admin_areas['config']['areas']['modsettings']['subsections']['glossary'] = array($txt['glossary']);
}

function glossary_settings(&$subActions)
{
$subActions['glossary'] = array($subActions, 'modify_glossary_settings');
}

function modify_glossary_settings()
{
global $txt, $scripturl, $context, $settings;

$context['page_title']     = $txt['glossary_settings'];
$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=glossary';

$config_vars = array(
array('check', 'enable_glossary_mod'),
array('check', 'enable_tooltips'),
'',
array('check', 'enable_numeric_glossary'),
array('check', 'enable_groups_in_glossary'),
'',
array('check', 'glossary_none_sensitive'),
array('text', 'glossary_separator', 1),
array('check', 'enable_bbc_tooltip_glossary'),
array('check', 'glossary_unique_word'),
array('check', 'glossary_show_in_message_default'),
array('check', 'glossary_tooltip_in_simpleportal'),
array('check', 'glossary_admin_context_menu'),
'',
array('int', 'glossary_definition_width',4),
array('int', 'glossary_word_width',4),
);

if ($return_config)
return $config_vars;

// Saving?
if (isset($_GET['save']))
{
checkSession();

saveDBSettings($config_vars);
redirectexit('action=admin;area=modsettings;sa=glossary');
}

prepareDBSettingContext($config_vars);
}



fixed opening code tag --Illori
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Doug Heffernan

Can you try this and see if it fixes the error:

// Hook for Admin options
function glossary_admin(&$admin_areas)
{
   global $txt;

   return $admin_areas['config']['areas']['modsettings']['subsections'] += array('glossary' => array(sprintf($txt['glossary'])));
}

function glossary_settings(&$subActions)
{
   return $subActions += array('glossary' => 'modify_glossary_settings');
}

function modify_glossary_settings()
{
   global $txt, $scripturl, $context, $settings;

   $context['page_title'] = $txt['glossary_settings'];

   $config_vars = array(
      array('check', 'enable_glossary_mod'),
      array('check', 'enable_tooltips'),
      '',
      array('check', 'enable_numeric_glossary'),
      array('check', 'enable_groups_in_glossary'),
      '',
      array('check', 'glossary_none_sensitive'),
      array('text', 'glossary_separator', 1),
      array('check', 'enable_bbc_tooltip_glossary'),
      array('check', 'glossary_unique_word'),
      array('check', 'glossary_show_in_message_default'),
      array('check', 'glossary_tooltip_in_simpleportal'),
      array('check', 'glossary_admin_context_menu'),
      '',
      array('int', 'glossary_definition_width',4),
      array('int', 'glossary_word_width',4),
   );

   if ($return_config)
      return $config_vars;

    if (isset($_GET['save']))
{
checkSession();

saveDBSettings($config_vars);

writeLog();

redirectexit('action=admin;area=modsettings;sa=glossary');
}

$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=glossary';

prepareDBSettingContext($config_vars);
}

Kindred


I see that you moved the $context['post_url'] lower in the code and added a writeLog()...   

Ok, that seems to be a step in the right direction and it no longer stops the content display...   
However, now it just displays the base "miscellaneous" category of modification settings, it doesn't display the glossary settings.
 
Also, I noticed the following,

in the set hooks
'integrate_modify_modifications' => 'glossary_settings',

I had a different (mistyped) name in my working copy which gave the above results.
(it noted that a function was defined for integration but was never called, in the error log)
However, if I put in a real function name, -- either glossary_settings or modify_glossary_settings, it fails, spectacularly

Fatal error: Uncaught Error: Call to undefined function prepareDBSettingContext() in /.../Sources/GlossaryHooks.php:149 Stack trace: #0 /.../Sources/Subs.php(5067): modify_glossary_settings(Array) #1 /.../Sources/ManageSettings.php(138): call_integration_hook('integrate_modif...', Array) #2 /.../Sources/Admin.php(502): ModifyModSettings() #3 /.../index.php(173): AdminMain() #4 {main} thrown in /.../Sources/GlossaryHooks.php on line 149
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Doug Heffernan

Can you attach the mod package here? Or pm it to me in private? I can take a look at it this week end. It is much easier, at leat for me, to have to the whole thing rather than parts and bits.

Kindred

PM sent with a link

BTW: I know the coding in the mail file needs to be cleaned up...   this is a 12 year old mod that I am trying to resurrect for 2.1 so the site I am using it on can update. SO, a little bit at a time.
(first bit was to replace the tables within tables within tables with divs)
(second bit is to change it to use hooks -- especially when working with RC versions of SMF)
(third but is to clean up the coding... because from my look during step 1, there are three almost identical routines that could likely be combined with variables instead of calling each one separately -- but don't worry about that)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: