Where are declarative settings located?

EDIT:
Looking in the server logs I can see that I have a file missing, but I am not sure what should what should go in this JS file.

"message":"Could not find resource testapp/js/testapp-main.js to load"

EDIT 2:
I figured out part of the problem. I thought that the section_id in the array returned by getSchema() was the name of my section in the settings view. I confused this with the title. The docs don’t really cover what these attributes are for so I was making assumptions.

Hello all!

I am trying to figure out how the declarative settings work. In my app I have some settings that are shown in the Administration Settings tab when you click on your profile icon. These settings are created using ISettings and an entry in the info.xml. I am wanting to switch this to the declarative settings if possible.

Here is my current test setup:

Test App
I created a test app using the app generator so I have a place to create the test settings.
I have created a Settings directory with a file called DeclarativeAdminSettings.php.

<?php

declare(strict_types=1);

namespace OCA\TestApp\Settings;

use OCP\IUser;
use OCP\Settings\DeclarativeSettingsTypes;
use OCP\Settings\IDeclarativeSettingsFormWithHandlers;

class DeclarativeAdminSettings implements IDeclarativeSettingsFormWithHandlers {

    public function __construct() {

    }

    public function getValue(string $fieldId, IUser $user): mixed {
	}

	public function setValue(string $fieldId, mixed $value, IUser $user): void {
	}

    public function getSchema(): array {
        return [
            'id' => 'test_app_declarative_settings_form',
            'priority' => 10,
            'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
            'section_id' => 'my_section_id',
            'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_INTERNAL,
            'title' => 'TestApp Settings Title',
            'description' => 'This is a description for the TestApp',
            'doc_url' => '',
            'fields' => [
                [
                    'id' => 'testapp_field_key',
                    'title' => 'A Setting',
                    'description' => 'Description for A Setting',
                    'type' => DeclarativeSettingsTypes::MULTI_SELECT,
                    'options' => ['foo', 'bar', 'baz'],
                    'placeholder' => 'Select something damn it',
                    'default' => ['foo', 'bar'],
                ]
            ]
       ];
    }
}

I then added the registration to the Application.php as follows:

<?php

declare(strict_types=1);

namespace OCA\TestApp\AppInfo;

use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCA\TestApp\Settings\DeclarativeAdminSettings;

class Application extends App implements IBootstrap {
	public const APP_ID = 'testapp';

	/** @psalm-suppress PossiblyUnusedMethod */
	public function __construct() {
		parent::__construct(self::APP_ID);
	}
	public function register(IRegistrationContext $context): void {
		$context->registerDeclarativeSettings(DeclarativeAdminSettings::class);
	}

	public function boot(IBootContext $context): void {
	}
}

This lines up almost exactly with the Nextcloud docs, but I can’t see these anywhere. I also looked at the Files app as an example since it has declarative settings, but again I don’t see the Files app admin settings in the Administrator Settings tab. I am pretty lost as to how these settings are supposed to work. Any help would be greatly appreciated.

I also looked at the Files app as an example since it has declarative settings, but again I don’t see the Files app admin settings in the Administrator Settings tab.

The existing server section is defined here:

And it is exposed in the UI today as the Basic settings section.

The example for the Files app you’re looking at located there under the heading Files compatibility.

Based on your code – assuming you adjust your section_id to server – I’d expect it to appear in the UI under Admin settings->Basic settings under the heading TestApp Settings Title.

1 Like

You are correct. I corrected the section id to security and can now see my settings as expected. I can access the values just as before. Thanks for your feedback.

1 Like