You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclarativeSettingsForm.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. declare(strict_types=1);
  3. namespace OCA\Testing\Settings;
  4. use OCP\Settings\DeclarativeSettingsTypes;
  5. use OCP\Settings\IDeclarativeSettingsForm;
  6. class DeclarativeSettingsForm implements IDeclarativeSettingsForm {
  7. public function getSchema(): array {
  8. return [
  9. 'id' => 'test_declarative_form',
  10. 'priority' => 10,
  11. 'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN, // admin, personal
  12. 'section_id' => 'additional',
  13. 'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_INTERNAL, // external, internal (handled by core to store in appconfig and preferences)
  14. 'title' => 'Test declarative settings class', // NcSettingsSection name
  15. 'description' => 'This form is registered with a DeclarativeSettingsForm class', // NcSettingsSection description
  16. 'doc_url' => '', // NcSettingsSection doc_url for documentation or help page, empty string if not needed
  17. 'fields' => [
  18. [
  19. 'id' => 'test_ex_app_field_7', // configkey
  20. 'title' => 'Multi-selection', // name or label
  21. 'description' => 'Select some option setting', // hint
  22. 'type' => DeclarativeSettingsTypes::MULTI_SELECT, // select, radio, multi-select
  23. 'options' => ['foo', 'bar', 'baz'], // simple options for select, radio, multi-select
  24. 'placeholder' => 'Select some multiple options', // input placeholder
  25. 'default' => ['foo', 'bar'],
  26. ],
  27. [
  28. 'id' => 'some_real_setting',
  29. 'title' => 'Choose init status check background job interval',
  30. 'description' => 'How often AppAPI should check for initialization status',
  31. 'type' => DeclarativeSettingsTypes::RADIO, // radio (NcCheckboxRadioSwitch type radio)
  32. 'placeholder' => 'Choose init status check background job interval',
  33. 'default' => '40m',
  34. 'options' => [
  35. [
  36. 'name' => 'Each 40 minutes', // NcCheckboxRadioSwitch display name
  37. 'value' => '40m' // NcCheckboxRadioSwitch value
  38. ],
  39. [
  40. 'name' => 'Each 60 minutes',
  41. 'value' => '60m'
  42. ],
  43. [
  44. 'name' => 'Each 120 minutes',
  45. 'value' => '120m'
  46. ],
  47. [
  48. 'name' => 'Each day',
  49. 'value' => 60 * 24 . 'm'
  50. ],
  51. ],
  52. ],
  53. [
  54. 'id' => 'test_ex_app_field_1', // configkey
  55. 'title' => 'Default text field', // label
  56. 'description' => 'Set some simple text setting', // hint
  57. 'type' => DeclarativeSettingsTypes::TEXT, // text, password, email, tel, url, number
  58. 'placeholder' => 'Enter text setting', // placeholder
  59. 'default' => 'foo',
  60. ],
  61. [
  62. 'id' => 'test_ex_app_field_1_1',
  63. 'title' => 'Email field',
  64. 'description' => 'Set email config',
  65. 'type' => DeclarativeSettingsTypes::EMAIL,
  66. 'placeholder' => 'Enter email',
  67. 'default' => '',
  68. ],
  69. [
  70. 'id' => 'test_ex_app_field_1_2',
  71. 'title' => 'Tel field',
  72. 'description' => 'Set tel config',
  73. 'type' => DeclarativeSettingsTypes::TEL,
  74. 'placeholder' => 'Enter your tel',
  75. 'default' => '',
  76. ],
  77. [
  78. 'id' => 'test_ex_app_field_1_3',
  79. 'title' => 'Url (website) field',
  80. 'description' => 'Set url config',
  81. 'type' => 'url',
  82. 'placeholder' => 'Enter url',
  83. 'default' => '',
  84. ],
  85. [
  86. 'id' => 'test_ex_app_field_1_4',
  87. 'title' => 'Number field',
  88. 'description' => 'Set number config',
  89. 'type' => DeclarativeSettingsTypes::NUMBER,
  90. 'placeholder' => 'Enter number value',
  91. 'default' => 0,
  92. ],
  93. [
  94. 'id' => 'test_ex_app_field_2',
  95. 'title' => 'Password',
  96. 'description' => 'Set some secure value setting',
  97. 'type' => 'password',
  98. 'placeholder' => 'Set secure value',
  99. 'default' => '',
  100. ],
  101. [
  102. 'id' => 'test_ex_app_field_3',
  103. 'title' => 'Selection',
  104. 'description' => 'Select some option setting',
  105. 'type' => DeclarativeSettingsTypes::SELECT, // select, radio, multi-select
  106. 'options' => ['foo', 'bar', 'baz'],
  107. 'placeholder' => 'Select some option setting',
  108. 'default' => 'foo',
  109. ],
  110. [
  111. 'id' => 'test_ex_app_field_4',
  112. 'title' => 'Toggle something',
  113. 'description' => 'Select checkbox option setting',
  114. 'type' => DeclarativeSettingsTypes::CHECKBOX, // checkbox, multiple-checkbox
  115. 'label' => 'Verify something if enabled',
  116. 'default' => false,
  117. ],
  118. [
  119. 'id' => 'test_ex_app_field_5',
  120. 'title' => 'Multiple checkbox toggles, describing one setting, checked options are saved as an JSON object {foo: true, bar: false}',
  121. 'description' => 'Select checkbox option setting',
  122. 'type' => DeclarativeSettingsTypes::MULTI_CHECKBOX, // checkbox, multi-checkbox
  123. 'default' => ['foo' => true, 'bar' => true, 'baz' => true],
  124. 'options' => [
  125. [
  126. 'name' => 'Foo',
  127. 'value' => 'foo', // multiple-checkbox configkey
  128. ],
  129. [
  130. 'name' => 'Bar',
  131. 'value' => 'bar',
  132. ],
  133. [
  134. 'name' => 'Baz',
  135. 'value' => 'baz',
  136. ],
  137. [
  138. 'name' => 'Qux',
  139. 'value' => 'qux',
  140. ],
  141. ],
  142. ],
  143. [
  144. 'id' => 'test_ex_app_field_6',
  145. 'title' => 'Radio toggles, describing one setting like single select',
  146. 'description' => 'Select radio option setting',
  147. 'type' => DeclarativeSettingsTypes::RADIO, // radio (NcCheckboxRadioSwitch type radio)
  148. 'label' => 'Select single toggle',
  149. 'default' => 'foo',
  150. 'options' => [
  151. [
  152. 'name' => 'First radio', // NcCheckboxRadioSwitch display name
  153. 'value' => 'foo' // NcCheckboxRadioSwitch value
  154. ],
  155. [
  156. 'name' => 'Second radio',
  157. 'value' => 'bar'
  158. ],
  159. [
  160. 'name' => 'Third radio',
  161. 'value' => 'baz'
  162. ],
  163. ],
  164. ],
  165. ],
  166. ];
  167. }
  168. }