Jump to content

Working with custom Forum settings


Go to solution Solved by CodePixel,

Recommended Posts

Hi, i'm trying to add few new settings to forums, i've managed to extend Forum Node to add settings to Forum creator/editor but i'm wondering if there's actually a way to create new column inside of forums_forums table or do i have to save those settings within new table generated by app? What i've made so far is this:
 

Hook extending IPS\forums\Forum node:

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class cpfiafi_hook_forum_settings extends _HOOK_CLASS_
{
	public function form( &$form )
	{
		parent::form($form);
		$form->addTab( 'tab_settings' );
		$form->addHeader( 'header_settings' );
		$form->add( new \IPS\Helpers\Form\Text('input_icon') );
	}
}

 

and i've stopped here while working on something else but this still troubles me on how to do it.

Link to comment
Share on other sites

9 hours ago, CodePixel.dev said:

but i'm wondering if there's actually a way to create new column inside of forums_forums table

If you are intending to release the resource on the MP then you shouldn't think about doing this and instead should...

9 hours ago, CodePixel.dev said:

...save those settings within new table generated by app?

To then retrieve those settings when loading a forum, you'd need to hook into constructLoadQuery in \IPS\forums\Forum and do something like this:

protected static function constructLoadQuery( $id, $idField, $extraWhereClause ){
	$parent = parent::constructLoadQuery($id, $idField, $extraWhereClause);
	$parent->join('your_table', 'your_table.forumid=forums_forum.id');
	return $parent;
}

 

Link to comment
Share on other sites

2 hours ago, Nathan Explosion said:

If you are intending to release the resource on the MP then you shouldn't think about doing this and instead should...

To then retrieve those settings when loading a forum, you'd need to hook into constructLoadQuery in \IPS\forums\Forum and do something like this:

protected static function constructLoadQuery( $id, $idField, $extraWhereClause ){
	$parent = parent::constructLoadQuery($id, $idField, $extraWhereClause);
	$parent->join('your_table', 'your_table.forumid=forums_forum.id');
	return $parent;
}

 

Okay this is good, exactly what i need to load data, question is how to save data in those additional fields?

Link to comment
Share on other sites

Back to the issue at hand, i've decided to make a new Node for that settings i want to add, everything cool and all, works and saves but i get error all the time that colum input_icon is undefined in field list, i tried doing unse

unset($values['input_icon']);

but that didn't help. I'm stuck completely and i don't know how to unset this variable so it doesn't try to save inside Forum node.

Link to comment
Share on other sites

class cpfiafi_hook_forum_settings extends _HOOK_CLASS_
{
	public function form( &$form )
	{
		parent::form($form);
		if(isset(\IPS\Request::i()->id)) {
			try
			{
				$icon = \IPS\cpfiafi\ForumIcon::load( \IPS\Request::i()->id );
			}
			catch ( \OutOfRangeException $e )
			{
				// $icon = new \IPS\cpfiafi\ForumIcon();
			}
			$form->addTab( 'tab_settings' );
			$form->addHeader( 'header_settings' );
			$form->add( new \IPS\Helpers\Form\Text('fa_icon') );
	
			if ( $values = $form->values() )
			{
				$icon->id = $this->id;
				$icon->fa_icon = $values['fa_icon'];
				$icon->save();

			}
		}
		
	}
}

 

Link to comment
Share on other sites

  • Solution

Problem solved, all i had to do was unset that value inside formatFormValues function.

/**
	 * [Node] Format form values from add/edit form for save
	 *
	 * @param	array	$values	Values from the form
	 * @return	array
	 */
	public function formatFormValues( $values )
	{
		if(isset($values['fa_icon']))
		{
			unset($values['fa_icon']);
		}
		return parent::formatFormValues( $values );
	}

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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