Jump to content

Developer Documentation

Adding AdminCP settings for login handlers

You will likely need to create settings for your login handler so when an admin sets it up they can provide keys, etc. There are two methods to assist with this. 

acpForm() can return an array of form fields allowing you to specify these settings, and testSettings() allows you to check the settings are correct. For example, to define a client ID setting you might do something like this:

/**
 * ACP Settings Form
 *
 * @param	string	$url	URL to redirect user to after successful submission
 * @return	array	List of settings to save - settings will be stored to core_login_handlers.login_settings DB field
 * @code
    return array( 'savekey'	=> new \IPS\Helpers\Form\[Type]( ... ), ... );
 * @endcode
 */
public function acpForm()
{
    return array(
        'example_client_id'	=> new \IPS\Helpers\Form\Text( 'example_client_id', ( isset( $this->settings['example_client_id'] ) ) ? $this->settings['example_client_id'] : '', TRUE )
    );
}

/**
 * Test Settings
 *
 * @return	bool
 * @throws	\InvalidArgumentException
 */
public function testSettings()
{
    if ( $this->settings['example_client_id'] == 'invalid id' )
    {
        throw new \InvalidArgumentException("The Client ID isn't correct.");
    }
    return TRUE;
}

And then you can simply access its value elsewhere using $this->settings['example_client_id'].

You can of course use custom validation callbacks for fields if appropriate, but often you will need testSettings() where there are multiple settings which work together.


  Report Document


×
×
  • Create New...