Add Custom Settings - mithra62/ee_debug_toolbar GitHub Wiki
A useful feature of the Debug Toolbar (EEDT) is that you can integrate your Panel's, or custom extension's, settings into the EEDT settings mechanism. Doing this has a couple advantages:
Note: this tutorial assumes you're already familiar with EEDT extension development and have read Creating custom debug panels
- All settings are consolidated under one Settings Form (the EEDT one)
- Developers don't have to bother creating their own custom Settings Forms for their debug add-ons.
- Users have automatic access override config options for your add-ons once installed.
Doing this requires 2 hooks be used in order to, first, register your settings with the EEDT settings object and, second, to create the form elements for updating.
A good point of reference for this tutorial would be the Performance Alerts extension that comes bundled
The Extensions
You'll have to create 2 Extensions for your EEDT Add-on
eedt_init_settings
This hook is to tell EEDT what your settings are and what values to use by default:
Be sure to always check for
ee()->extensions->last_call
like in the below to ensure you get all the other set settings.
namespace DebugToolbar\MemoryHistory\Extensions;
class EeDebugToolbarInitSettings extends AbstractHook
{
/**
* @var array|string[]
*/
protected array $default_settings = [
'memory_history_position' => "top right",
];
/**
* @param array $default_settings
* @return array
*/
public function process(array $default_settings): array
{
$default_settings = (ee()->extensions->last_call != '' ? ee()->extensions->last_call : $default_settings);
return array_merge($default_settings, $this->default_settings);
}
}
eedt_settings_form
This hook allows complete access to the EEDT Settings form object. Note the Form object is an instance of the ExpressionEngine CP/Form Service
namespace DebugToolbar\MemoryHistory\Extensions;
use ExpressionEngine\Library\CP\Form;
class EeDebugToolbarSettingsForm extends AbstractHook
{
/**
* @param Form $form
* @return Form
*/
public function process(Form $form): Form
{
$settings = $this->toolbar->getSettings();
$options = [
'bottom left' => 'bottom-left',
'top left' => 'top-left',
'top right' => 'top-right',
'bottom right' => 'bottom-right'
];
$field_group = $form->getGroup('eedt_memory_history.form.header.settings');
$field_set = $field_group->getFieldSet('eedt_memory_history.form.position');
$field_set->setDesc('eedt_memory_history.form.desc.form.position');
$field = $field_set->getField('memory_history_position', 'select');
$field->setChoices($options)
->setValue($settings['memory_history_position']);
return $form;
}
}