Jump to content

Plugin to add new field to forum configuration


Andrzej Pindor

Recommended Posts

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.

Link to comment
Share on other sites

	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.

Link to comment
Share on other sites

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":

image.png.d3609e00bb7876e62e42309038cede35.png

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"?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...