Jump to content

Plugin settings - Populate select boxes


ChrisVanMeer

Recommended Posts

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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' 
) );

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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)
{
}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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' 
) );

 

Link to comment
Share on other sites

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.

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...