ExternalConnectionFormTrait
Forms of third-party connections, one form per installed connection.
A component factory builds the forms by row id (connectionForm-<id>). The user cannot change
the number of rows: connections are created by installation (SQL), not in the admin.
Form fields derive from the connection type registry (getFields()):
- Text gives
addText, Number a numeric field, BooladdCheckbox, - Secret gives
addPassword, which never prints the stored value; an empty submit keeps the stored value, a filled one overwrites it, a checkedclear_<field>deletes it.
IMPORTANT: required fields are validated only for an enabled connection; a disabled one may stay unfinished.
IMPORTANT: field names carry a prefix (field_, clear_) so that a type field can never
collide with enabled or other form controls.
Groups (ConnectionTypeInterface::getGroup()): enabling a connection disables the other
enabled connections of the same group, as they are alternatives (e.g. reCAPTCHA v2 and v3).
One Api operation in one DB transaction (saveExclusive) saves the connection and disables
the alternatives; on failure nothing changes.
Table of Contents
Constants
- CLEAR_PREFIX : string = 'clear_'
- FIELD_PREFIX : string = 'field_'
- SESSION_OPENED : string = 'opened'
- SESSION_SECTION : string = 'admin.externalConnections'
- Session section + key remembering which card was just saved (consumed on next render).
Methods
- createComponentConnectionForm() : Multiplier<string|int, Form>
- addConnectionField() : void
- buildConnectionTitles() : array<int, string>
- connectionControl() : BaseControl|null
- createConnectionForm() : Form
- isConnectionSecretStored() : bool
- saveConnectionForm() : bool
- setConnectionFormDefaults() : void
- validateConnectionForm() : void
- Validates required fields only for an enabled connection.
Constants
CLEAR_PREFIX
private
string
CLEAR_PREFIX
= 'clear_'
FIELD_PREFIX
private
string
FIELD_PREFIX
= 'field_'
SESSION_OPENED
private
string
SESSION_OPENED
= 'opened'
SESSION_SECTION
Session section + key remembering which card was just saved (consumed on next render).
private
string
SESSION_SECTION
= 'admin.externalConnections'
Methods
createComponentConnectionForm()
protected
createComponentConnectionForm() : Multiplier<string|int, Form>
Return values
Multiplier<string|int, Form>addConnectionField()
private
addConnectionField(Form $form, ExternalConnection $connection, ConnectionTypeInterface $type, ConnectionField $field) : void
Parameters
- $form : Form
- $connection : ExternalConnection
- $type : ConnectionTypeInterface
- $field : ConnectionField
buildConnectionTitles()
private
buildConnectionTitles(mixed $types) : array<int, string>
Parameters
- $types : mixed
-
type codes returned by the Api operation
Return values
array<int, string> —translated connection titles
connectionControl()
private
connectionControl(Form $form, string $name) : BaseControl|null
Parameters
- $form : Form
- $name : string
Return values
BaseControl|nullcreateConnectionForm()
private
createConnectionForm(int $id) : Form
Parameters
- $id : int
Return values
FormisConnectionSecretStored()
private
isConnectionSecretStored(ExternalConnection $connection, string $field) : bool
Parameters
- $connection : ExternalConnection
- $field : string
Return values
boolsaveConnectionForm()
private
saveConnectionForm(int $id, ArrayHash<string|int, mixed> $values) : bool
Parameters
- $id : int
- $values : ArrayHash<string|int, mixed>
Return values
boolsetConnectionFormDefaults()
private
setConnectionFormDefaults(Form $form, ExternalConnection $connection, ConnectionTypeInterface $type) : void
Parameters
- $form : Form
- $connection : ExternalConnection
- $type : ConnectionTypeInterface
validateConnectionForm()
Validates required fields only for an enabled connection.
private
validateConnectionForm(Form $form, ExternalConnection $connection, ConnectionTypeInterface $type) : void
A secret field counts as filled also when a value is already stored (an empty submit keeps it), unless the clear checkbox is checked.
Parameters
- $form : Form
- $connection : ExternalConnection
- $type : ConnectionTypeInterface