From: Marcel Werk Date: Tue, 30 Jul 2024 09:19:11 +0000 (+0200) Subject: Add code example for `AclFormField` X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fe1432493cd3c72bfcaba507607aebf6698e51c1;p=GitHub%2FWoltLab%2Fwoltlab.github.io.git Add code example for `AclFormField` --- 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`