Make it easier to define URLs for Menu and remove an unnessary parameter #6140
Labels
Task
Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Milestone
Already for a while I do not like the way we are defining the URL of a menu item as well as by the
$displayForCurrentUser
param of theMenuAbstract::add()
method:I just wanted to write a blog post about Controller + Menu and noticed this ones more so I am going to make this easier now. Therefore I will deprecate the
add()
method in favor of newaddItem()
method which no longer has the$displayForCurrentUser
argument. Theadd()
method will be removed in Piwik 3.0 I think. It is easy to stay backwards compatible here. Added a test for this.One should use an if condition instead of the boolean parameter:
To make the URL parameter easier I am going to introduce three new methods:
The first two methods will detect the current module automatically so we remove a lot of duplicated code. The third method will make sure the module actually exist and is activated. The methods are also better readable than the array structure and allows us to change the generated array in the future without having to change the plugins.
Example:
Note: A while ago I added also new methods to no longer having to know the translation keys of menu items so it is even shorter:
The text was updated successfully, but these errors were encountered: