From fe1432493cd3c72bfcaba507607aebf6698e51c1 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 30 Jul 2024 11:19:11 +0200 Subject: [PATCH] Add code example for `AclFormField` --- docs/php/api/form_builder/form_fields.md | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/php/api/form_builder/form_fields.md b/docs/php/api/form_builder/form_fields.md index 3f392cd9..bba30599 100644 --- a/docs/php/api/form_builder/form_fields.md +++ b/docs/php/api/form_builder/form_fields.md @@ -267,6 +267,36 @@ A category name of `null` signals that no category filter is used. `AclFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the relevant ACL object type id into the `$parameters` array directly using `{$objectProperty}_aclObjectTypeID` as the array key. The relevant database object action method is expected, based on the given ACL object type id, to save the ACL option values appropriately. +#### Example + +The following source code creates an `AclFormField` with the object type `foo.bar.acl`: + +```php +FormContainer::create('aclContainer') + ->label('foo.bar.acl') + ->appendChildren([ + AclFormField::create('acl') + ->objectType('foo.bar.acl') + ]) +``` + +After submitting the form, the id of the object type is passed to the DatabaseObjectAction and can be used there to process the data with the help of the `ACLHandler`. + +```php +use wcf\data\AbstractDatabaseObjectAction; +use wcf\system\acl\ACLHandler; + +class FooAction extends AbstractDatabaseObjectAction { + public function create() { + $object = parent::create(); + + if (!empty($this->parameters['acl_aclObjectTypeID'])) { + ACLHandler::getInstance()->save($object->getObjectID(), $this->parameters['acl_aclObjectTypeID']); + } + } +} +``` + ### `ButtonFormField` -- 2.20.1