Jump to content

Plugin settings - Populate select boxes


ChrisVanMeer

Recommended Posts

Posted

Hi,

How can I populate a select box in my plugin settings page with i.e. all the forums?
I now have a field where one would put the forum ID in, but it would be nicer for the user to be able to select the forum from a dropdown box and then saves the ID as setting.

Chris
 

Posted

Ok got that one sorted with the following code:

$form->add( new \IPS\Helpers\Form\Node( 'setting_name', \IPS\Settings::i()-> setting_name ? \IPS\Settings::i()->setting_name : 0, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'use_cat_forum' ), NULL, NULL, NULL, 'setting_name' ) );

Now I need to find out how to display all profile fields (and a seperate one for the profile field groups)

Posted
6 minutes ago, ChrisVanMeer said:

Now I need to find out how to display all profile fields (and a seperate one for the profile field groups)

The same way but use 

IPS\core\ProfileFields\Group

as class param

Posted

Awesome, got that one sorted as well.
I now see the full node and I want to populate three \IPS\Settings values >

  1. With the profile field group id
  2. With the profile field id
  3. With the profile field name

I can't seem to find documentation on how to use one Node / Select box in the settings.php to store to multiple settings values.
Plus, how can I echo the contents of a \IPS\Settings value, so I can see what values are being stored in it?

Posted

Not sure what you mean.

To select multiple values add 

'multiple' => true,

to options 

$form->add( new \IPS\Helpers\Form\Node( 
	'setting_name', 
	\IPS\Settings::i()-> setting_name ? \IPS\Settings::i()->setting_name : 0, 
	FALSE, 
	array( 
		'multiple' => true, 
		'class' => 'IPS\forums\Forum', 
		'zeroVal' => 'use_cat_forum' 
	), 
	NULL, 
	NULL, 
	NULL, 
	'setting_name' 
) );

 

Posted

Ok I will try to clarify.

I have this form below.
2017-12-20_09-58-44.thumb.png.5b46b3a8572a907971282ff8c2ef1633.png
Let's say that I click on About Me

I then want the following to happen when I save the settings

  1. Save the ID of the Personal Information group to \IPS\Settings::i()->cvm_profile_group_id
  2. Save the ID of the About Me field to \IPS\Settings::i()->cvm_profile_field_id
  3. Save the name About Me to \IPS\Settings::i()->cvm_profile_field_name
Posted
10 minutes ago, ChrisVanMeer said:

I then want the following to happen when I save the settings

Why?

10 minutes ago, ChrisVanMeer said:
  1. Save the name About Me to \IPS\Settings::i()->cvm_profile_field_name

It's multilang value

about.thumb.jpg.7a9fc8a6532cbef0f658d32ec7026e5f.jpg

Store only field ID. Then get the field by ID. No need create separate setting for each field param :)

 

Posted
14 minutes ago, newbie LAC said:

Why?

Because I have the following class:

	public function get_required_profile_field()
	{
		try
		{
          $setting = \IPS\Member::loggedIn()->profileFields();

          $groupID = \IPS\Settings::i()->cvm_profile_field_group_id;
          $groupID = "core_pfieldgroups_$groupID";

          $fieldID = \IPS\Settings::i()->cvm_profile_field_field_id;
          $fieldID = "core_pfield_$fieldID";

		  $field = $setting[$groupID][$fieldID];
        
          if ($field != "") {
              return true;
          } else {
              return false;
          }
        }
		catch ( \RuntimeException $e )
		{
			throw $e;
		}
	}

I need to fill at least the core_pfieldgroups_<id> and core_pfield_<id>

Posted
1 hour ago, ChrisVanMeer said:

I need to fill at least the core_pfieldgroups_<id> and core_pfield_<id>

 

1 hour ago, newbie LAC said:

Then get the field by ID.

try
{
	$fieldObj = \IPS\core\ProfileFields\Field::load(\IPS\Settings::i()->cvm_profile_field_field_id);

	$fieldID = "core_pfield_{$fieldObj->_id}";
	$groupID = "core_pfieldgroups_{$fieldObj->group_id}";
}
catch (\Exception $e)
{
}

 

Posted

Almost got it, but can't find the equivalent of array( 'class' => 'IPS\core\ProfileFields\Group' ) for the single profile field ID.
When I now select About Me, it saves the ID of the group, not the field.

Posted
16 hours ago, ChrisVanMeer said:

Almost got it, but can't find the equivalent of array( 'class' => 'IPS\core\ProfileFields\Group' ) for the single profile field ID.

From my previous post

Quote

\IPS\core\ProfileFields\Field

 

16 hours ago, ChrisVanMeer said:

When I now select About Me, it saves the ID of the group, not the field.

I reported about that sometime ago

The stored value is 1 but should be 1.s

Posted
4 hours ago, newbie LAC said:

\IPS\core\ProfileFields\Field

$form->add( new \IPS\Helpers\Form\Node( 'cvm_profile_field_field_id', \IPS\Settings::i()->cvm_profile_field_field_id ? \IPS\Settings::i()->cvm_profile_field_field_id : 0, FALSE, array( 'class' => 'IPS\core\ProfileFields\Field' ), NULL, NULL, NULL, 'cvm_profile_field_field_id' ) );

2017-12-21_11-59-24.png.d6db53cd02cdd186458f2220ffe58948.png

Posted

Congratulations! You found a bug.

Quote

Access to undeclared static property: IPS\core\ProfileFields\Field::$nodeTitle

If the form field type doesn't matter for you use IPS\Helpers\Form\Select

$form->add( new \IPS\Helpers\Form\Select( 
	'cvm_profile_field_field_id', 
	\IPS\Settings::i()->cvm_profile_field_field_id ? \IPS\Settings::i()->cvm_profile_field_field_id : 0, 
	FALSE, 
	array( 
		'options' => \IPS\core\ProfileFields\Field::rootsAsArray()
	), 
	NULL, 
	NULL, 
	NULL, 
	'cvm_profile_field_field_id' 
) );

 

Posted
14 minutes ago, newbie LAC said:

Congratulations! You found a bug.

Ok, I will report it.

One final question: how do I retrieve the name of the profile field by it's id?

$fieldObj = \IPS\core\ProfileFields\Field::load(\IPS\Settings::i()->cvm_profile_field_field_id);
$fieldName = $fieldObj->      ;

I can't seem to find where you can retrieve a list of all these properties.

Posted
23 hours ago, newbie LAC said:

Congratulations! You found a bug.

Bug reported and just got back the following:

Quote

Thank you for your report, I have added the node title property for the node model. This change will be included in a future release.

 

Archived

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

  • Recently Browsing   0 members

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