DeclarativeSettingsForm.php 5.6 KB

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