updateMenuExtensions()

Forcedly updates the top-right Scrivito menu.

Copy
Scrivito.updateMenuExtensions()

With Scrivito.extendMenu, custom menu items may depend on an external service, which requires asynchronous communication.

Scrivito automatically updates the top-right menu on every content-related change, however, other asynchronous changes are not automatically reflected. In such advanced cases, Scrivito.updateMenuExtensions comes to the rescue.

Whenever a state change in your application affects a menu extension, call Scrivito.updateMenuExtensions. This forces the menu extensions to be re-evaluated. Afterwards, the menu will be in sync with the application’s current state.

Examples

Conditionally show an “openStatistics” menu item. The menu item must only show up if the HTTP API listening at “/api/adminToken” responds with an OK status:

Copy
let userIsAdmin;

Scrivito.extendMenu(menu => {
  if (userIsAdmin) {
    menu.insert({ id: 'openStatistics' });
  }
});

userIsAdmin = (await fetch('/api/adminToken')).ok;
Scrivito.updateMenuExtensions();

Enable a “betaFeature” item only after the user executed the toggleBeta() command in the browser console:

Copy
Scrivito.extendMenu(menu => {
  menu.insert({
    id: 'betaFeature',
    enabled: !!top.isBeta
  });
});

top.toggleBeta = () => {
  top.isBeta = !top.isBeta;
  Scrivito.updateMenuExtensions();
}