Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Sonya* Posted November 21, 2016 Posted November 21, 2016 Hi, I would like extend a method and need to execute my code AFTER the parent method is run but before it returns. The method is searchResult(). I have to manipulate $status object BEFORE it used in template. public static function searchResult( array $indexData, array $authorData, array $itemData, array $containerData = NULL, array $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments=FALSE ) { $status = static::constructFromData( $itemData ); $status->reputation = $reputationData; $profileOwner = isset( $itemData['profile'] ) ? $itemData['profile'] : NULL; $profileOwnerData = $profileOwner ?: $authorData; $status->_url = \IPS\Http\Url::internal( "app=core&module=members&controller=profile&id={$profileOwnerData['member_id']}&status={$itemData['status_id']}&type=status", 'front', 'profile', array( $profileOwnerData['members_seo_name'] ) ); // ################ HERE ################ return \IPS\Theme::i()->getTemplate( 'statuses', 'core', 'front' )->statusContainer( $status, $authorData, $profileOwner, $view == 'condensed' ); } It works, when I patch the code at the place marked with HERE. And now how do I add the code to the hook? static public function searchResult( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments=false ) { return call_user_func_array( 'parent::searchResult', func_get_args() ); } I cannot add it before return call_user_func_array as $status object does not exist yet. And I cannot add it after return logically. Thanks.
Daniel F Posted November 21, 2016 Posted November 21, 2016 Could you describe what you're trying to change in the status object? There are several ways to manipulate the status object. 1. You could override status::constructFromData, set a custom variable inside of the searchResult method, then call parent::searchResult and customize the status::constructFromData response if your custom variable is set, which indicates that it was called from the searchResult method... 2. You could just override status::constructFromData and modify it always 3. You could create a theme hook to run custom code before the template is returned... ( That's the way which I would recommend )
Ilya Hoilik Posted November 21, 2016 Posted November 21, 2016 You could create a Theme Hook (instead of Code Hook) and select core → front → statuses in the Template Group field. Open ipsThemeCoreFrStatuses.php file located in the hooks folder. Now you can create statusContainer() method which accepts nothing. Then use func_get_args() function to get all passed arguments, modify what you need and then return the parent method. This example replaces all statuses with 'something': ipsThemeCoreFrStatuses.php
Sonya* Posted November 21, 2016 Author Posted November 21, 2016 5 hours ago, Daniel F said: Could you describe what you're trying to change in the status object? I have implemented tags functionality on status with code hooks. It works and is saved in search index. I can also search now for tags in statuses. The only thing I miss: displaying tags in template for activity stream statusContainer(). The tags are in $indexData['index_tags'] parameter of searchResult(). But $indexData is not used in template statusContainer (see the method above). That's why I need to add it to $status manually.
Sonya* Posted November 21, 2016 Author Posted November 21, 2016 Sorry, I have just realized there is a function $status->tags() that can be used in template. No need for code hook at this place
Recommended Posts
Archived
This topic is now archived and is closed to further replies.