The label is displayed on the Gui whenever the user interacts with the field.
- Required
- Type
String
todo
Config Key: fields
<?php
// CLIENT_CONFIG/config/fields.php
return [
'some_field' => [
'field' => [
/**
* Configuration for the field comes here
*/
],
'values' => [
/**
* Configuration for the Values come here
*/
]
],
// add more fields
];
WARNING
Not all fields support all options a field might have. Within the list of options we've marked the fields-types where the specific option is not applicable.
todo
field.labelThe label is displayed on the Gui whenever the user interacts with the field.
Stringfield.descriptionThe description is used in later versions of SCP Gui to display a tooltip text for the field use to the user.
String''field.placeholderIf the visual field repesentation (e.g. a text-box) supports a placeholder, SCP uses this configuration.
String''field.iconWhen the filter pane is collapsed SCP is showing icons instead of names for the gui filter. Here you can define the icon by using names of the Material Design Icon Library (opens new window).
String'help'field.groupIf you have a lot of fields, group them in categories to make the life of your users easier. Setting the group key
just adds a new group to the property list.
Stringfield.filterfield.typeFields need to have a type to let SCP know which kind of form field should be displayed to the user.
Stringselect, tag, date, text, textarea, materials, bool, autocompletefield.filteringEnabledIf enabled the Gui will display a gui-filter inside the filters section to allow users searching through this meta data field.
Booleantruematerialsfield.requiredIf set to true the field needs to be filled out.
Booleanfalsefield.triggersFieldUpdateIf you set this to true a field change will force the Gui to revalidate all business rules, filters, etc. to display
proper fields. If you want to e.g. display specific fields based on values of other fields, the fields which are controlling
visibility state should have this option enabled.
Booleanfalsematerialsfield.propertyListEnabledIf this option is set to true, the field is displayed inside the property pane. For fields you want to use without
exposing the value to your users, set this option to false.
Booleantruefield.sortingEnabledIf you want users to be able to use a field for sorting, just enable this configuration and the Gui will display an appropriate option.
Booleanfalsematerialsfield.disabledfield.options.updatesIf you want to update some field configuration with the field value of the current field, you can do so by using this configuration:
<?php
// CLIENT_CONFIG/config/fields.php
return [
'start_date' => [
'field' => [
'type' => 'date',
'options' => [
'updates' => [
// you can use multiple update calls
[
// this option can make use of the dot-notation to deeply change
// the configuration of a field
// in this example we are setting the minimal date of the "end_date"
// field to the date value of our "start_date" field
'field' => 'end_date',
'option' => 'options.minDate'
]
],
]
],
// ...
]
];
field.defaultPreferenceSet this to true if you want SCP to fallback to the default values of the field when something has changed – even if there is a value stored.
This is useful if you want to control field values based on some other fields but still want to let user change the data afterwards.
Booleanfalseselect, boolfield.alwaysEnabledFields get disabled by the field.disabled configuration and the fact if the material is editable or not (check
Material Options for further information).
If a field is enabled by default (disabled set to false) but the meta-data of the material is not editable
due to a Material Option all fields will get disabled by default.
If you want to enable some fields to be always enabled, no matter what happens – use this field and set it to true or
a Filter.
Boolean | Filterfalsefield.selectorThe selector is a path to the database column where the data will be saved. Usually this is not required as we automatically use a JSON based field for storing field values.
Stringfield_values.{name_of_field}WARNING
Use this option with caution as wrong configuration may harm the integrity of the SCP instance.
field.triggersBriefingUpdateIf you want SCP to force the content apps state to reload the material data it has already loaded from SCP Core, you should
set this fields to true.
Booleanfalsematerialsfield.conditionsFields may require proper validation to help users adding correct values. You can add Conditions here to let SCP know what it should check for.
field.pass_throughtodo
field.pass_throughtodo
Materials FieldThe materials field type allows users to attach other materials to the current one.
This field has some special options:
field.queryThis configuration may contain a query definition which is used by SCP to search for eligible materials to be linked to this meta data field.
<?php
// CLIENT_CONFIG/config/fields.php
return [
'related_material' => [
'field' => [
// ...
'query' => [
// search for material which have the same type as the current one
'materialType' => '$selectedMaterial.material_type_id',
// search for material created by the current user
'created_by_showcase_user_id' => '$user.id'
],
]
],
];
falsematerialsThe query can contain dynamic variables which should follow the dot-notation and can refer to $user and $selectedMaterial.
field.maximumThis is the maximum of allowed materials to attach to this field.
IntegerDate FieldUnder the hood SCP uses the awesome Flatpickr (opens new window) which means that you can pass all kind of Flatpickr Options (opens new window) to the options array of the field definition to fully control how the Date fields works:
<?php
// CLIENT_CONFIG/config/fields.php
return [
'reviewer' => [
'field' => [
// ...
'type' => 'autocomplete',
'settings' => [
'route' => '/showcase-users/search',
'display' => '%first% %last%',
'value' => '%id%',
'max' => 4
],
]
],
];
Autocomplete FieldThe auto-complete field is a very generic one which is mainly used to search for users. But it can be easily used to extend the Gui to search for some kind of data in JSON based APIs as well.
It supports the following options
field.settings.routeThe route which is used by a HTTP Get request to get the JSON based data when the user enters something to the input.
field.settings.displayWhat should be displayed to the user when the results are consumed. You can pass over some tokens like
%key% %another_key% which will use the JSON data from the Get request to display the given data.
field.settings.valueThe value field also uses the tokens which are used for the field.settings.display property. The resulting value will be
used and stored in SCPs database.
field.settings.maxDetermines how much results will be displayed to the user once the Get results has been fetched.
<?php
// CLIENT_CONFIG/config/fields.php
return [
'related_material' => [
'field' => [
// ...
'type' => 'date',
'options' => [
// we want to also pick the time
// see https://flatpickr.js.org/options/
'enableTime' => true,
],
]
],
];
Some field types require setting a list of values from a user can choose from.
This is typical for tag and select fields which are quite common.
Also text based fields can have a default value which will be used as a default text.
<?php
// CLIENT_CONFIG/config/fields.php
return [
'language' => [
'field' => [
// ... some configuration
],
'values' => [
[
/** This is a field value set */
'filter' => [
'language' => 'switzerland'
],
'values' => [
'de' => [
'name' => 'German',
'default' => true,
],
'fr' => [
'name' => 'French',
'default' => false,
],
// additional values
]
],
[
/**
* This is a field value set too, which is
* used if nothing else match
*/
'filter' => [],
'values' => [
'en' => [
'name' => 'English',
'default' => true,
],
]
],
]
],
// add more fields
];
filterA value set will be chosen by evaluating the given filter – if the filter matches the current material SCP select the configured values and makes them available to the use to choose from.
valuesThe values key has to contain an associative array which needs to expose keys which are used by SCP to store the selected
value. From the example above, selecting "German" will lead to a stored value de inside the database.
[String => [ ... ]]values.*.nameThe name is used as label for the value the user is choosing from.
Stringvalues.*.defaultIf a value is set as default (true) it will be used as the a pre-selection.
BooleanfalseFields which are based on just a single value bool, textarea, text can have a default value too:
<?php
// CLIENT_CONFIG/config/fields.php
return [
'description' => [
'field' => [
// some configuration
],
'values' => [
[
'filter' => [], // matches always
'value' => 'This is the default text',
],
]
],
// add more fields
];
You can set condition on fields to force the user to follow some rules while giving some input.
<?php
// CLIENT_CONFIG/config/fields.php
return [
'approval_code' => [
'field' => [
// ...
'type' => 'text',
'conditions' => [
[
/**
* This is a condition
*/
'rules' => [
// which is using two different rules
'max' => 20,
'regex' => '^[0-9]{3}-[A-Z]+'
],
// and will output this message if one of the rules
// are not followed by the user
'message' => 'Please follow the guideline 123-XXX'
],
[
// here could come a new condition with an additional message
]
]
]
],
];
We use vee-validate (opens new window) under the hood – checkout their rules which can be used inside SCP natively.
Limited Support
Not all fields can make use of conditions – there is not a real list of which one can be used on why type, but with just common sense, you'll find the right answer 😃
todo
<?php
// CLIENT_CONFIG/config/fields.php
return [
'approval_code' => [
'field' => [
// ...
'type' => 'text',
'conditions' => [
[
'rules' => [
'min' => 3,
],
'message' => 'Your text is less than 3 characters long!'
],
[
'rules' => [
'max' => 10,
],
'message' => 'Your text is more than 10 characters long!'
],
[
'rules' => [
'alpha' => [] // no options (default!)
],
'message' => 'Your text does contain non alphanumeric characters'
],
[
'rules' => [
'alpha_dash' => [] // no options (default!)
],
'message' => 'Only alphanumeric values and underscores and dashes'
],
[
'rules' => [
'alpha_num' => [] // no options (default!)
],
'message' => 'Please only numbers and characters, no special chars'
],
[
'rules' => [
'alpha_spaces' => [] // no options (default!)
],
'message' => 'Only alphabetic characters and spaces please'
],
[
'rules' => [
'between' => [] // no options (default!)
],
'message' => 'Your numeric value needs to be between 1 and 5'
],
[
'rules' => [
'digits' => [] // no options (default!)
],
'message' => 'Numeric value with 5 digits please'
],
[
'rules' => [
'email' => [] // no options (default!)
],
'message' => 'You have to enter a valid email address'
],
[
'rules' => [
'in' => ['first', 'second']
],
'message' => 'Please use only one of the given values: first, second'
],
[
'rules' => [
'not_in' => ['first', 'second']
],
'message' => 'Please do not use one of the given values: first, second'
],
[
'rules' => [
'max_value' => 10
],
'message' => 'Your numeric value needs to be less or equal than 10'
],
[
'rules' => [
'min_value' => 10
],
'message' => 'Your numeric value needs to be at least than 10'
],
[
'rules' => [
// for backslashes use \\\\ (four backslashes)
'regex' => '^([0-9]+)$'
],
'message' => 'Only numbers please'
],
[
'rules' => [
'url' => false // true = with http://
],
'message' => 'Please enter a valid url (without http://...)'
],
]
]
],
];
todo