Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
*/
protected $authenticationPluginType = 'authentication';

/**
* Menu instances container.
*
* @var AbstractMenu[]
* @since __DEPLOY_VERSION__
*/
protected $menus = [];

/**
* The menu factory
*
Expand Down Expand Up @@ -525,12 +533,23 @@ public function getMenu($name = null, $options = array())
$options['app'] = $this;
}

if (array_key_exists($name, $this->menus))
{
return $this->menus[$name];
}

if ($this->menuFactory === null)
{
@trigger_error('Menu factory must be set in 5.0', E_USER_DEPRECATED);
$this->menuFactory = $this->getContainer()->get(MenuFactoryInterface::class);
}

return $this->menuFactory->createMenu($name, $options);
$this->menus[$name] = $this->menuFactory->createMenu($name, $options);

// Make sure the abstract menu has the instance too, is needed for BC and will be removed with version 5
AbstractMenu::$instances[$name] = $this->menus[$name];

return $this->menus[$name];
}

/**
Expand Down
4 changes: 3 additions & 1 deletion libraries/src/Menu/AbstractMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ abstract class AbstractMenu
* @var AbstractMenu[]
*
* @since 1.7
*
* @deprecated 5.0 Use the MenuFactoryInterface from the container instead
*/
protected static $instances = array();
public static $instances = array();

/**
* User object to check access levels for
Expand Down