Logo
  • General contributor guidelines
  • App development
    • Introduction
    • Tutorial
    • App upgrade guide
    • Bootstrapping
    • NPM
    • JavaScript APIs
    • Request lifecycle
    • View
    • Storage and database
    • Changelog
    • Classloader
    • Code signing
    • App metadata
    • Navigation and pre-app configuration
      • Adding a navigation entry
      • Further pre-app configuration
      • Initialization events
    • App store publishing
    • User management
    • Two-factor providers
    • Events
    • Background jobs (Cron)
    • Settings
    • Notifications
    • Nextcloud Flow
    • Logging
    • Repair steps
    • Public Pages
    • Testing
    • Coding Style
    • PSR
    • API reference
  • Design guidelines
  • Android application development
  • Client APIs
  • Core development
  • Bugtracker
  • Help and communication
  • API reference
Nextcloud latest Developer Manual
  • »
  • App development »
  • Navigation and pre-app configuration
  • Edit on GitHub

Navigation and pre-app configuration

Adding a navigation entry

Navigation entries for apps can be created by adding a navigation section to the appinfo/info.xml file, containing the name, order and route the navigation entry should link to. For details on the XML schema check the app store documentation.

<navigation>
    <name>MyApp</name>
    <route>myapp.page.index</route>
    <order>0</order>
</navigation>

Further pre-app configuration

The appinfo/app.php is the first file that is loaded and executed in Nextcloud. Depending on the purpose of the app it is usually used to setup things that need to be available on every request to the server, like Background jobs (Cron) and hooks registrations. This is how an example appinfo/app.php could look like:

<?php

// execute OCA\MyApp\BackgroundJob\Task::run when cron is called
\OC::$server->getJobList()->add('OCA\MyApp\BackgroundJob\Task');

// execute OCA\MyApp\Hooks\User::deleteUser before a user is being deleted
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\MyApp\Hooks\User', 'deleteUser');

Initialization events

Often apps do not need to load their JavaScript and CSS on every page. For this purpose there are several events emitted that an app can act upon.

  • OCAFiles::loadAdditionalScripts (string): loaded on the files list page

  • OCAFiles_Sharing::loadAdditionalScripts (string): loaded on the public sharing page

  • OCAFiles_Sharing::loadAdditionalScripts::publicShareAuth (string): loaded on the public share authentication page

  • OCPAppFrameworkHttpTemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS (constant): loaded when a template response is finished

  • OCPAppFrameworkHttpTemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN (constant): loaded when a template response is finished for a logged in user

<?php

$dispatcher = \OC::$server->getEventDispatcher();

$dispatcher->addListener(
    OCP\AppFramework\Http\TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
    function() {
        \OCP\Util::addScript('myapp', 'script');
        \OCP\Util::addStyle('myapp', 'style');
    }
);
Previous Next

© Copyright 2022 Nextcloud GmbH.

Read the Docs v: latest
Versions
16
17
18
19
stable
latest
Downloads
On Read the Docs
Project Home
Builds