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.

RegisterDeclarativeSettingsListener.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace OCA\Testing\Listener;
  4. use OCP\EventDispatcher\Event;
  5. use OCP\EventDispatcher\IEventListener;
  6. use OCP\Settings\DeclarativeSettingsTypes;
  7. use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
  8. /**
  9. * @template-implements IEventListener<DeclarativeSettingsRegisterFormEvent>
  10. */
  11. class RegisterDeclarativeSettingsListener implements IEventListener {
  12. public function __construct() {
  13. }
  14. public function handle(Event $event): void {
  15. if (!($event instanceof DeclarativeSettingsRegisterFormEvent)) {
  16. // Unrelated
  17. return;
  18. }
  19. $event->registerSchema('testing', [
  20. 'id' => 'test_declarative_form_event',
  21. 'priority' => 20,
  22. 'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
  23. 'section_id' => 'additional',
  24. 'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_INTERNAL,
  25. 'title' => 'Test declarative settings event', // NcSettingsSection name
  26. 'description' => 'This form is registered via the RegisterDeclarativeSettingsFormEvent', // NcSettingsSection description
  27. 'fields' => [
  28. [
  29. 'id' => 'event_field_1',
  30. 'title' => 'Why is 42 this answer to all questions?',
  31. 'description' => 'Hint: It\'s not',
  32. 'type' => DeclarativeSettingsTypes::TEXT,
  33. 'placeholder' => 'Enter your answer',
  34. 'default' => 'Because it is',
  35. ],
  36. [
  37. 'id' => 'feature_rating',
  38. 'title' => 'How would you rate this feature?',
  39. 'description' => 'Your vote is not anonymous',
  40. 'type' => DeclarativeSettingsTypes::RADIO, // radio, radio-button (NcCheckboxRadioSwitch button-variant)
  41. 'label' => 'Select single toggle',
  42. 'default' => '3',
  43. 'options' => [
  44. [
  45. 'name' => 'Awesome', // NcCheckboxRadioSwitch display name
  46. 'value' => '1' // NcCheckboxRadioSwitch value
  47. ],
  48. [
  49. 'name' => 'Very awesome',
  50. 'value' => '2'
  51. ],
  52. [
  53. 'name' => 'Super awesome',
  54. 'value' => '3'
  55. ],
  56. ],
  57. ],
  58. ],
  59. ]);
  60. }
  61. }