Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Andrzej Pindor Posted September 27, 2017 Posted September 27, 2017 I'm trying to create training plugin which will add custom field to forum configuration (forum edit form). My field will be YesNo type and I want it to show only when user selects forum type "Redirect" I created install.php step1: public function step1() { $columnName = "flt_newWindow"; $columnExist = \IPS\Db::i()->checkForColumn("forum_forums", $columnName); if(!$columnExist){ \IPS\Db::i()->addColumn("forum_forums", array( 'name' => $columnName, 'type' => 'BOOLEAN', 'null' => FALSE, 'default' => FALSE, 'comment' => 'ForumLinkTarget plugin column')); } return TRUE; } and now I'm trying to add class hook to class: \applications\forums\sources\Forum\Forum.php I created hook: class hook1 extends _HOOK_CLASS_ { /** * [Node] Add/Edit Form * * @param \IPS\Helpers\Form $form The form * @return void */ public function form( &$form ) { call_user_func_array( 'parent::form', array(&$form) ); $form->add( new \IPS\Helpers\Form\YesNo( 'forum_redirect_new_window', $this->id ? $this->redirect_new_window : FALSE, FALSE, array(), NULL, NULL, NULL, 'forum_redirect_new_window' ) ); } I figured out I need to deal with this code from Forum.php: $form->add( new \IPS\Helpers\Form\Radio( 'forum_type', $type, TRUE, array( ... ... 'toggles' => array( ... 'redirect' => array( 'forum_password_on', 'forum_redirect_url', 'forum_redirect_hits' //add my field here But how can I push my field to this array so it will be visible when user selects "redirect" type? My field is not shown at all.
Adriano Faria Posted September 27, 2017 Posted September 27, 2017 I don’t think you can do that. You would need to add your field to the “forum type” field toggle s. Anyway, just saying without see the script itself as I’m on a mobile device now.
Martin A. Posted September 27, 2017 Posted September 27, 2017 public function __construct() { call_user_func_array( 'parent::__construct', func_get_args() ); if ( $this->name == 'forum_type' AND \IPS\Dispatcher::i()->controllerLocation == 'admin' { $this->options['toggles'][] = "forum_redirect_new_window"; } } Hook into IPS\Helpers\Form\Radio as well. If current location is 'admin' and the form element key is 'forum_type', add you field to the options list.
Andrzej Pindor Posted September 27, 2017 Author Posted September 27, 2017 1 hour ago, Martin A. said: public function __construct() { call_user_func_array( 'parent::__construct', func_get_args() ); if ( $this->name == 'forum_type' AND \IPS\Dispatcher::i()->controllerLocation == 'admin' { $this->options['toggles'][] = "forum_redirect_new_window"; } } Hook into IPS\Helpers\Form\Radio as well. If current location is 'admin' and the form element key is 'forum_type', add you field to the options list. ok, but my new filed is added in section "Tags": how can I add this to the "Settings" section of edit forum form? EDIT: ok, I think now I've figure it out. Edit form is build "in order" so if method form in IPS\forums\_Forum creates it in once, I cannot override this method. I must hook into another place, ex. method "add" in IPS\Helpers\_Form and override then function add "listening" for adding field from form which i'm interested in and add my custom field when field is added which I'm interested in to be "after"?
Adriano Faria Posted September 27, 2017 Posted September 27, 2017 This will make it appear after forum_redirect_hits: $form->add( new \IPS\Helpers\Form\YesNo( 'forum_redirect_new_window', $this->id ? $this->redirect_new_window : FALSE, FALSE, array(), NULL, NULL, NULL, 'forum_redirect_new_window' ), 'forum_redirect_hits' );
Andrzej Pindor Posted September 27, 2017 Author Posted September 27, 2017 I accepted @Martin A. but @Adriano Faria answer was very helpful also! Thank you. Now I must figure out saving this form
Adriano Faria Posted September 27, 2017 Posted September 27, 2017 Just now, Andrzej Pindor said: Now I must figure out saving this form What are you extending exactly? If you're extending \IPS\forums\Forum::form(), then you can save on formatFormValues().
Andrzej Pindor Posted September 27, 2017 Author Posted September 27, 2017 1 minute ago, Adriano Faria said: What are you extending exactly? If you're extending \IPS\forums\Forum::form(), then you can save on formatFormValues(). Thanks. Best way is to watch in source code or is it documented somewhere? I'm reading developer documentation section but it's pretty simple..
bfarber Posted September 28, 2017 Posted September 28, 2017 We don't have every method documented - for plugins especially your best bet is to look at the source code. I also wanted to point out, you don't need to overload the add() method just to control *where* your form element is getting inserted. /** * Add Input * * @param \IPS\Helpers\Form\FormAbstract $input Form element to add * @param string|NULL $after The key of element to insert after * @param string|NULL $tab The tab to insert onto * @return void */ public function add( $input, $after=NULL, $tab=NULL ) When you add your NEW element, just pass the second param to specify which existing element to add it after. Otherwise without this, it is added as the next form field in the form.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.