======== Settings ======== .. sectionauthor:: Arthur Schiwon An app can register both admin settings as well as personal settings. Admin ----- For Nextcloud 10 the admin settings page got reworked. It is not a long list anymore, but divided into sections, where related settings forms are grouped. For example, in the **Sharing** section are only settings (built-in and of apps) related to sharing. Settings form ------------- For the settings form, three things are necessary: 1. A class implementing ``\OCP\Settings\ISettings`` 2. A template 3. The implementing class specified in the app's info.xml Below is an example for an implementor of the ISettings interface. It is based on the survey_client solution. .. code-block:: php collector = $collector; $this->config = $config; $this->l = $l; $this->dateTimeFormatter = $dateTimeFormatter; $this->jobList = $jobList; } /** * @return TemplateResponse */ public function getForm() { $lastSentReportTime = (int) $this->config->getAppValue('survey_client', 'last_sent', 0); if ($lastSentReportTime === 0) { $lastSentReportDate = $this->l->t('Never'); } else { $lastSentReportDate = $this->dateTimeFormatter->formatDate($lastSentReportTime); } $lastReport = $this->config->getAppValue('survey_client', 'last_report', ''); if ($lastReport !== '') { $lastReport = json_encode(json_decode($lastReport, true), JSON_PRETTY_PRINT); } $parameters = [ 'is_enabled' => $this->jobList->has('OCA\Survey_Client\BackgroundJobs\MonthlyReport', null), 'last_sent' => $lastSentReportDate, 'last_report' => $lastReport, 'categories' => $this->collector->getCategories() ]; return new TemplateResponse('yourappid', 'admin', $parameters); } /** * @return string the section ID, e.g. 'sharing' */ public function getSection() { return 'survey_client'; } /** * @return int whether the form should be rather on the top or bottom of * the admin section. The forms are arranged in ascending order of the * priority values. It is required to return a value between 0 and 100. */ public function getPriority() { return 50; } } The parameters of the constructor will be resolved and an instance created automatically on demand, so that the developer does not need to take care of it. ``getSection`` is supposed to return the section ID of the desired admin section. Currently, built-in values are ``server``, ``sharing``, ``encryption``, ``logging``, ``additional`` and ``tips-tricks``. Apps can register sections of their own (see below), and also register into sections of other apps. ``getPriority`` is used to order forms within a section. The lower the value, the more on top it will appear, and vice versa. The result depends on the priorities of other settings. Nextcloud will look for the templates in a template folder located in your apps root directory. It should always end on .php, in this case ``templates/admin.php`` would be the final relative path. .. code-block:: php

t('Your app')); ?>

t('Only administrators are allowed to click the red button')); ?>

checked="checked" />

t('Things to define')); ?>

$data) { ?>

checked="checked" />

t('Last report')); ?>

t('Sent on: %s', [$_['last_sent']])); ?>
Then, the implementing class should be added to the info.xml. Settings will be registered upon install and update. When settings are added to an existing, installed and enabled app, it should be made sure that the version is increased so Nextcloud can register the class. It is only possible to register one ISettings implementor. For a more complex example using embedded templates have a look at the implementation of the **user_ldap** app. Section ------- It is also possible that an app registers its own section. This should be done only if there is not fitting corresponding section and the apps settings form takes a lot of screen estate. Otherwise, register to "additional". Basically, it works the same way as with the settings form. There are only two differences. First, the interface that must be implemented is ``\OCP\Settings\ISection``. Second, a template is not necessary. An example implementation of the ISection interface: .. code-block:: php l = $l; } /** * returns the ID of the section. It is supposed to be a lower case string * * @returns string */ public function getID() { return 'yourappid'; //or a generic id if feasible } /** * returns the translated name as it should be displayed, e.g. 'LDAP / AD * integration'. Use the L10N service to translate it. * * @return string */ public function getName() { return $this->l->t('Translatable Section Name'); } /** * @return int whether the form should be rather on the top or bottom of * the settings navigation. The sections are arranged in ascending order of * the priority values. It is required to return a value between 0 and 99. */ public function getPriority() { return 80; } } Also the section must be registered in the app's info.xml. Personal ^^^^^^^^ Registering personal settings follows and old style yet. Within the app intialisation (e.g. in appinfo/app.php) a method must be called: .. code-block:: php