A form containing an editor throws the moment the page is opened, not on submit, if its app and key do not name a real extension.
The symptom
OutOfBoundsException: Admin #0 /applications/myapp/modules/admin/.../controller.php(340): IPS\Helpers\Form\Editor->__construct(...)
The exception message is the key alone, with no mention of the app, which makes it read like a missing language string.
The cause
new Editor( 'body', '', TRUE, array( 'app' => 'myapp', 'key' => 'Admin' ) )
This resolves eagerly to applications/myapp/extensions/core/EditorLocations/Admin.php. If that file does not exist, the constructor throws.
The fix
Either register the extension, or point at an existing one. For an admin-authored email or announcement body, core/Admin is what core's own Bulk Mail uses:
new Editor( 'body', $value, TRUE, array(
'app' => 'core',
'key' => 'Admin',
'autoSaveKey' => 'myapp-thing-' . $id,
'tags' => array( '{member_name}' => 'Member name' ),
) )
The tags option adds an insert menu to the editor toolbar, which is a better home for placeholders than a help box above the field.
Testing it
This fails inside an ACP controller, which cannot be instantiated from the command line. A static check — reading the source for app/key pairs and confirming the file exists — catches it without a browser.
Recommended Comments