Problem
Now that #2880152: Convert custom menu links to be revisionable is in, changes to menu links in non-live workspaces are not showing up. Making changes, and publishing changes from non-live to live works well. But it's not possible to preview the changes on the site's frontend.
This is caused by the menu tree cache, because rendered menus needs to be cached per workspace.
The basic problems, which are solved in the current patch are as follows:
- Menu links are discovered and stored in the
menu_tree
table. The MenuTreeStorage service caches a menu's links with a cid which contains all the parameters used in the SELECT query to load the links from the mentioned menu_tree table. This happens insideMenuTreeStorage::loadTreeData()
. If we want to see workspace specific links in a tree, the cached tree data needs to be workspace specific and to achieve this we need to override the tree storage in order to make the cid workspace specific. If we don't do that, a cached menu tree saved inside a workspace can and would be retrieved in the live workspace and would possibly show menu link contents (incl. link targets) that are not actually available on the live version of the site. - The DB table
menu_tree
is not an entity table, thus it's not "revisionable" and hence can't be workspace specific. This table contains columns like "title" and "description" (and possibly others), which are also available on the `menu_link_content` entity. The values from the menu_link_content entity are in fact written/copied into the table atMenuLinkContent::postSave()
. In order to implement workspace specific menu links, we have to be loading title and description etc. from menu_link_content revisions in a workspace, so we can't use the title, description etc. that is normally loaded by the MenuTreeStorage::loadLinks() method directly from the DB table. In order to tackle this, we have to overwrite that method, load the links from the DB first (via the original storage's method) and then override those links with what is stored in the workspace specific menu_link_content revisions.
Proposed solution
Cache menus per workspace.
We also have to overwrite certain menu link values loaded in the MenuTreeStorage::loadLinks()
as these values come directly out of the menu_tree
table and are NOT workspace-specific nor contain values of the menu_link_content
entity revisions.
API changes
None.