Skip to content

Commit fe14324

Browse files
committed
Add code example for AclFormField
1 parent 60f71fc commit fe14324

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/php/api/form_builder/form_fields.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,36 @@ A category name of `null` signals that no category filter is used.
267267
`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.
268268
The relevant database object action method is expected, based on the given ACL object type id, to save the ACL option values appropriately.
269269

270+
#### Example
271+
272+
The following source code creates an `AclFormField` with the object type `foo.bar.acl`:
273+
274+
```php
275+
FormContainer::create('aclContainer')
276+
->label('foo.bar.acl')
277+
->appendChildren([
278+
AclFormField::create('acl')
279+
->objectType('foo.bar.acl')
280+
])
281+
```
282+
283+
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`.
284+
285+
```php
286+
use wcf\data\AbstractDatabaseObjectAction;
287+
use wcf\system\acl\ACLHandler;
288+
289+
class FooAction extends AbstractDatabaseObjectAction {
290+
public function create() {
291+
$object = parent::create();
292+
293+
if (!empty($this->parameters['acl_aclObjectTypeID'])) {
294+
ACLHandler::getInstance()->save($object->getObjectID(), $this->parameters['acl_aclObjectTypeID']);
295+
}
296+
}
297+
}
298+
```
299+
270300

271301
### `ButtonFormField`
272302

0 commit comments

Comments
 (0)