Allow to filter marketplace by module ID (#6436)

This commit is contained in:
Yuriy Bakhtin 2023-07-17 13:10:30 +04:00 committed by GitHub
parent 36c4cff0a0
commit 5c5a73dce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -103,7 +103,7 @@ class InstalledModuleControls extends Menu
$this->addEntry(new MenuLink([
'id' => 'info',
'label' => Yii::t('AdminModule.base', 'Show in Marketplace'),
'url' => ['/marketplace/browse', 'keyword' => $this->module->id, 'tags' => ''],
'url' => ['/marketplace/browse', 'id' => $this->module->id],
'icon' => 'info-circle',
'sortOrder' => 600,
]));

View File

@ -17,6 +17,7 @@ use Yii;
class FilterService
{
private Module $module;
private string $moduleId;
private int $categoryId;
private array $tags;
@ -24,6 +25,8 @@ class FilterService
{
$this->module = $module;
$this->moduleId = $moduleId ?? Yii::$app->request->get('id', '');
$this->categoryId = $categoryId ?? Yii::$app->request->get('categoryId', 0);
if (is_array($tags)) {
@ -36,7 +39,25 @@ class FilterService
public function isFiltered(): bool
{
return $this->isFilteredByCategory() && $this->isFilteredByTags();
return $this->isFilteredById() &&
$this->isFilteredByCategory() &&
$this->isFilteredByTags();
}
public function isFilteredById(): bool
{
if (empty($this->moduleId)) {
// All modules
return true;
}
if ($this->moduleId === $this->module->id) {
// Force tags to "All" on filter by module ID
$this->tags = [];
return true;
}
return false;
}
public function isFilteredByCategory(): bool

View File

@ -82,7 +82,7 @@ class ModuleFilters extends DirectoryFilters
{
switch ($filter) {
case 'tags':
return 'uninstalled';
return self::isFilteredById() ? '' : 'uninstalled';
}
return parent::getDefaultValue($filter);
@ -129,4 +129,9 @@ class ModuleFilters extends DirectoryFilters
return $this->render('module-update-info', $info);
}
public static function isFilteredById(): bool
{
return Yii::$app->request->get('id', '') !== '';
}
}