Improve menu link adding#8032
Conversation
|
@yurabakhtin I'm a bit ambivalent about method chaining. On the one hand, it's very nice, but on the other hand, it's confusing when there are too many options and it's unclear which ones are required and which ones are optional. In general, imo it would be best to enforce mandatory (or very typical) attributes via the constructor/create method and make "optional" attributes available via method chaining. $this->addEntry(MenuLink::create(Yii::t('AdminModule.base', 'Spaces'), ['/admin/space'])
->id('spaces')
->icon('dot-circle-o')
->sortOrder(400)
->active('admin', 'space')
->visible(Yii::$app->user->can([ManageSpaces::class, ManageSettings::class]));The second route parameter What do you think about this change? |
|
@luke- Ok, for me it is enough too, main idea is to replace the array code to functions, because IDE suggests what methods are allowed for the object when I write Maybe we should use the method name as
I see |
👍
Maybe there are some JS links, so I think we should allow |
|
@luke- New changes a91a2fe. $this->addEntry(MenuLink::instance(Yii::t('AdminModule.base', 'Modules') . $this->getMarketplaceUpdatesBadge())
->url(['/admin/module'])If the method name |
# Conflicts: # CHANGELOG.md # protected/humhub/modules/admin/widgets/AdminMenu.php # protected/humhub/modules/ui/menu/MenuLink.php
|
@yurabakhtin Thanks, looks good! If the PR isn't urgent, I'd like to put it on hold. We also wanted to take a closer look at the link/button classes, and it really makes sense to standardize them here as well. |
|
@luke- Yes, it is not urgent, but it would be good to refactor the menu link adding in future. |
What kind of change does this PR introduce? (check at least one)
The PR fulfills these requirements:
developbranch, not themasterbranch if no hotfixOther information:
We have many code in the array format like this:
I prefer to apply options by methods as we have for bootstrap Button, so new code will be:
I have started this only for the widget
AdminMenu, but it is used in almost all modules, if you will approve it then I will do this modification when I work on this https://github.com/humhub/humhub-internal/issues/1042.