Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Adriano Faria Posted May 7, 2019 Posted May 7, 2019 I implemented the IPS\Content\ItemTopic trait in my apps but two of them has a particularity: the topic should not be created right after the item is submitted; user must add questions/answers or prizes then click in a button so the topic is created. I mean, that's how it was on <4.3 because I didn't have the syncTopic(() on createFromForm; I had it on my controller function. So the question is: how can I prevent the topic from being created right after submit the item when using the ItemTopic trait? I can't return parent in createFromForm on my item model, otherwise the topic will be created. Tks.
bfarber Posted May 8, 2019 Posted May 8, 2019 public static function createFromForm( $values, \IPS\Node\Model $container = NULL, $sendNotification = TRUE ) { $containercolumn = static::containerForumIdColumn(); $item = parent::createFromForm( $values, $container, $sendNotification ); if ( \IPS\Application::appIsEnabled('forums') and $item->container()->$containercolumn and !$item->hidden() ) { $item->syncTopic(); } return $item; } There's no default/built-in way to do what you are talking about, but you might be able to fudge it. You could unset the forum ID value in the container temporarily and then set it back afterwards, for instance.
Adriano Faria Posted May 8, 2019 Author Posted May 8, 2019 58 minutes ago, bfarber said: You could unset the forum ID value in the container temporarily and then set it back afterwards, for instance. I’ll try that. Tks.
Ryan Ashbrook Posted May 8, 2019 Posted May 8, 2019 If you overload the createFromForm method in your class, then the one in the trait will not run (see \IPS\downloads\File where we need to alias the changeAuthor method from the trait in order to call it, because that class defines it's own changeAuthor method). See: https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.precedence https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.conflict
Adriano Faria Posted May 8, 2019 Author Posted May 8, 2019 Just now, Ryan Ashbrook said: If you overload the createFromForm method in your class, then the one in the trait will not run Yes, tried that but didn’t know what to return... if false, NULL, etc. always ended up in error.
Ryan Ashbrook Posted May 8, 2019 Posted May 8, 2019 public static function createFromForm( $values, \IPS\Node\Model $container = NULL, $sendNotification = TRUE ) { return parent::createFromForm( $values, $container, $sendNotification ); } In this case, the "parent" here is \IPS\Content\Item (or whatever class you're extending), not the trait, so syncTopic will not run. Think of methods from traits as "fillers." If the method doesn't exist in the class using the trait, then the trait fills it in. If it does, then it does nothing unless you resolve the conflict (like we do in \IPS\downloads\File).
Adriano Faria Posted May 9, 2019 Author Posted May 9, 2019 21 hours ago, Ryan Ashbrook said: In this case, the "parent" here is \IPS\Content\Item (or whatever class you're extending), not the trait, so syncTopic will not run. Think of methods from traits as "fillers." If the method doesn't exist in the class using the trait, then the trait fills it in. If it does, then it does nothing unless you resolve the conflict (like we do in \IPS\downloads\File). No luck. Just tried and it still creates the topic. Regarding Downloads, I don't see how it was resolved there. Can you elaborate? 22 hours ago, bfarber said: There's no default/built-in way to do what you are talking about, but you might be able to fudge it. You could unset the forum ID value in the container temporarily and then set it back afterwards, for instance. No luck too. Topic created.
Adriano Faria Posted May 10, 2019 Author Posted May 10, 2019 I removed the topic trait as it doesn't allow me to create the topic in another moment. Tks.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.