Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Aiwa Posted February 11, 2018 Posted February 11, 2018 There appear to be limitations on the plugins hook system vs application hook system. For example, setting the default tab on profile view. The following works with an Application. Extending \IPS\core\modules\front\members\profile. Ultimately, the manage() method looks to see if a tab has already been set. If so, display it. Using the below, I can modify the request parameter for tab and set it to what I want. protected function manage() { try { if(\IPS\Settings::i()->steam_default_tab && !isset(\IPS\Request::i()->tab)) { \IPS\Request::i()->tab = 'node_steam_steamprofile'; } return parent::manage(); } catch ( \RuntimeException $e ) { if ( method_exists( get_parent_class(), __FUNCTION__ ) ) { return parent::manage(); } else { throw $e; } } } Let's follow this through \IPS\core\modules\front\members\profile manage() and see what \IPS\Request::i()->tab has it it... You'll see the added variable $request has the correct 'node_steam_steamprofile' profile extension in it and we're setting the active tab to what came in with \IPS\Request Let's look at Plugins.... Same thing. Extending \IPS\core\modules\front\members\profile... Only difference in the code is the IF statement, removes a setting bit specific to the previous application, and instead of hard-coding a value for 'tab', I'm using a setting. I've checked the DB, the setting exists and is populated. See below for screenshot. protected function manage() { try { if(!isset(\IPS\Request::i()->tab)) { \IPS\Request::i()->tab = \IPS\Settings::i()->dpt_default; } return parent::manage(); } catch ( \RuntimeException $e ) { if ( method_exists( get_parent_class(), __FUNCTION__ ) ) { return parent::manage(); } else { throw $e; } } } Let's follow this through \IPS\core\modules\front\members\profile manage() and see what \IPS\Request::i()->tab has it it... NULL. At which point we'll always get 'Activity' as the default tab. Any comment on the scope of those limitations? When we should always use an application vs when it's possible to use a plugin? Pre-requisites that have to be met for a plugin? Otherwise, it looks to me like anything that would rely on a code hook needs to be an Application. Including something that could be done with only a handful of lines of code.
bfarber Posted February 12, 2018 Posted February 12, 2018 The hooks system functions independent of plugins vs applications, as in hooks are a different "thing" that both can make use of. Behind the scenes they are mapped and loaded the exact same way. IOW, what you are showing should work, so there must be another factor at play. 1) Check your hooks.php file in /plugins/ and make sure (a) this hook is mapped and set to be loaded properly, and (b) there are no other hooks that may be causing issues 2) After that, I would start debugging. See if your plugin hook file is loaded. var_dump() the setting value to make sure it's set properly, and so on.
Aiwa Posted February 13, 2018 Author Posted February 13, 2018 13 hours ago, bfarber said: The hooks system functions independent of plugins vs applications, as in hooks are a different "thing" that both can make use of. Behind the scenes they are mapped and loaded the exact same way. IOW, what you are showing should work, so there must be another factor at play. 1) Check your hooks.php file in /plugins/ and make sure (a) this hook is mapped and set to be loaded properly, and (b) there are no other hooks that may be causing issues 2) After that, I would start debugging. See if your plugin hook file is loaded. var_dump() the setting value to make sure it's set properly, and so on. hooks.php <?php return array ( '\\IPS\\core\\modules\\front\\members\\Profile' => array ( 293 => array ( 'file' => 'plugins/defaultprofiletab/hooks/defaultProfileTab.php', 'class' => 'hook293', ), ), ); Lesson learned, don't create hooks in the middle of the night and let your keyboard autocorrect / auto-capitalize things for you. \IPS\core\module\front\members\profile not Profile Thanks @All Astronauts and @bfarber for saving my sanity. Oddly enough, the hook editor isn't smart enough to solve this for you. When i hit edit, it knows what class to pull, but doesn't fix anything for you. You'd think this would be smart enough to throw an error rather than make you think it's working.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.