Skip to content

Commit 79dadca

Browse files
committed
Add code examples for specific form fields
1 parent 0760f68 commit 79dadca

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

docs/php/api/form_builder/form_fields.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,26 +472,54 @@ The class implements `IAttributeFormField` and `ICssClassFormField`.
472472

473473
Specifically for this form field, there is the `IsNotClickedFormFieldDependency` dependency with which certain parts of the form will only be processed if the relevent button has not clicked.
474474

475+
Example:
476+
477+
```php
478+
ButtonFormField::create('example')
479+
->buttonLabel('foo.bar.example')
480+
```
481+
475482

476483
### `CaptchaFormField`
477484

478485
`CaptchaFormField` is used to add captcha protection to the form.
479486

480487
You must specify a captcha object type (`com.woltlab.wcf.captcha`) using the `objectType()` method.
481488

489+
Example:
490+
491+
```php
492+
CaptchaFormField::create('captcha')
493+
->objectType(CAPTCHA_TYPE)
494+
```
495+
482496

483497
### `ColorFormField`
484498

485499
`ColorFormField` is used to specify RGBA colors using the `rgba(r, g, b, a)` format.
486500
The class implements `IImmutableFormField`.
487501

502+
Example:
503+
504+
```php
505+
ColorFormField::create('example')
506+
->label('foo.bar.example')
507+
->value('rgba(1,1,1,1)')
508+
```
509+
488510

489511
### `ContentLanguageFormField`
490512

491513
`ContentLanguageFormField` is used to select the content language of an object.
492514
Fields of this class are only available if multilingualism is enabled and if there are content languages.
493515
The class implements `IImmutableFormField`.
494516

517+
Example:
518+
519+
```php
520+
ContentLanguageFormField::create()
521+
```
522+
495523

496524
### `LabelFormField`
497525

@@ -502,13 +530,29 @@ The `labelGroup(ViewableLabelGroup $labelGroup)` and `getLabelGroup()` methods a
502530
Additionally, there is the static method `createFields($objectType, array $labelGroups, $objectProperty = 'labelIDs)` that can be used to create all relevant label form fields for a given list of label groups.
503531
In most cases, `LabelFormField::createFields()` should be used.
504532

533+
Example:
534+
535+
```php
536+
LabelFormField::create('example')
537+
->objectType('foo.bar.example.object.type')
538+
->labelGroup(LabelHandler::getInstance()->getLabelGroup($groupID))
539+
```
540+
505541

506542
### `OptionFormField`
507543

508544
`OptionFormField` is an [item list form field](#itemlistformfield) to set a list of options.
509545
The class implements `IPackagesFormField` and only options of the set packages are considered available.
510546
The default label of instances of this class is `wcf.form.field.option` and their default id is `options`.
511547

548+
Example:
549+
550+
```php
551+
OptionFormField::create()
552+
->description('foo.bar.example')
553+
->packageIDs([1, 2])
554+
```
555+
512556

513557
### `SimpleAclFormField`
514558

@@ -520,6 +564,19 @@ The default label of instances of this class is `wcf.form.field.option` and thei
520564

521565
The `SimpleAclFormField` supports inverted permissions, allowing the administrator to grant access to all non-selected users and groups. If this behavior is desired, it needs to be enabled by calling `supportInvertedPermissions`. An `invertPermissions` key containing a boolean value with the users selection will be provided together with the ACL values when saving the field.
522566

567+
Example:
568+
569+
```php
570+
SimpleAclFormField::create('example')
571+
->label('foo.bar.example')
572+
->supportInvertedPermissions(true)
573+
->value([
574+
'allowAll' => false,
575+
'user' => [1, 2],
576+
])
577+
```
578+
579+
523580
### `SingleMediaSelectionFormField`
524581

525582
`SingleMediaSelectionFormField` is used to select a specific media file.
@@ -530,6 +587,13 @@ The following methods are specific to this form field class:
530587
- `imageOnly($imageOnly = true)` and `isImageOnly()` can be used to set and check if only images may be selected.
531588
- `getMedia()` returns the media file based on the current field value if a field is set.
532589

590+
Example:
591+
592+
```php
593+
SingleMediaSelectionFormField::create('example')
594+
->label('foo.bar.example')
595+
```
596+
533597

534598
### `TagFormField`
535599

@@ -540,6 +604,13 @@ The default label of instances of this class is `wcf.tagging.tags` and their def
540604

541605
`TagFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the array with entered tag names into the `$parameters` array directly using the object property as the array key.
542606

607+
Example:
608+
609+
```php
610+
TagFormField::create()
611+
->objectType('foo.bar.example.object.type')
612+
```
613+
543614

544615
### `UploadFormField`
545616

@@ -552,6 +623,16 @@ The field supports additional settings:
552623
- `imageOnly($imageOnly = true)` and `isImageOnly()` can be used to ensure that the uploaded files are only images.
553624
- `allowSvgImage($allowSvgImages = true)` and `svgImageAllowed()` can be used to allow SVG images, if the image only mode is enabled (otherwise, the method will throw an exception). By default, SVG images are not allowed.
554625

626+
Example:
627+
628+
```php
629+
UploadFormField::create('example')
630+
->label('foo.bar.example')
631+
->maximum(1)
632+
->imageOnly(true)
633+
```
634+
635+
555636
#### Provide value from database object
556637

557638
To provide values from a database object, you should implement the method `get{$objectProperty}UploadFileLocations()` to your database object class. This method must return an array of strings with the locations of the files.
@@ -568,26 +649,53 @@ The class implements `IAutoCompleteFormField`, `IAutoFocusFormField`, `IImmutabl
568649
While the user is presented the names of the specified users in the user interface, the field returns the ids of the users as data.
569650
The relevant `UserProfile` objects can be accessed via the `getUsers()` method.
570651

652+
Example:
653+
654+
```php
655+
UserFormField::create('example')
656+
->label('foo.bar.example')
657+
```
658+
571659

572660
### `UserPasswordField`
573661

574662
`UserPasswordField` is a form field for users' to enter their current password.
575663
The class implements `IAttributeFormField`, `IAttributeFormField`, `IAutoCompleteFormField`, `IAutoFocusFormField`, and `IPlaceholderFormField`
576664

665+
Example:
666+
667+
```php
668+
UserPasswordField::create()
669+
->autocomplete('current-password')
670+
```
671+
577672

578673
### `UserGroupOptionFormField`
579674

580675
`UserGroupOptionFormField` is an [item list form field](#itemlistformfield) to set a list of user group options/permissions.
581676
The class implements `IPackagesFormField` and only user group options of the set packages are considered available.
582677
The default label of instances of this class is `wcf.form.field.userGroupOption` and their default id is `permissions`.
583678

679+
Example:
680+
681+
```php
682+
UserGroupOptionFormField::create()
683+
->packageIDs([1, 2])
684+
```
685+
584686

585687
### `UsernameFormField`
586688

587689
`UsernameFormField` is used for entering one non-existing username.
588690
The class implements `IAttributeFormField`, `IImmutableFormField`, `IMaximumLengthFormField`, `IMinimumLengthFormField`, `INullableFormField`, and `IPlaceholderFormField`.
589691
As usernames have a system-wide restriction of a minimum length of 3 and a maximum length of 100 characters, these values are also used as the default value for the field’s minimum and maximum length.
590692

693+
Example:
694+
695+
```php
696+
UsernameFormField::create('example')
697+
->label('foo.bar.example')
698+
```
591699

592700

593701
## Wysiwyg form container

0 commit comments

Comments
 (0)