Skip to content

Commit 5a2620d

Browse files
committed
Internal: List plugins with the menu_administrator region assign when loading admin index blocks
1 parent b073848 commit 5a2620d

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

public/main/inc/lib/plugin.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,13 @@ public function getPluginInfo($pluginName, $forced = false)
457457
foreach ([$pluginName, strtolower($pluginName), ucfirst(strtolower($pluginName))] as $dir) {
458458
$path = $pluginPath . "$dir/plugin.php";
459459
if (is_file($path)) {
460-
require_once $path;
460+
$fileToLoad = true;
461+
include_once $path;
461462
$pluginDir = $dir;
462463
break;
463464
}
464465
}
465466

466-
$instance = null;
467467
if (isset($plugin_info['plugin_class']) && class_exists($plugin_info['plugin_class'], false)) {
468468
$cls = $plugin_info['plugin_class'];
469469
$instance = method_exists($cls, 'create') ? $cls::create() : new $cls();

src/CoreBundle/Controller/Admin/IndexBlocksController.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66

77
namespace Chamilo\CoreBundle\Controller\Admin;
88

9+
use AppPlugin;
910
use Chamilo\CoreBundle\Controller\BaseController;
1011
use Chamilo\CoreBundle\Entity\Page;
1112
use Chamilo\CoreBundle\Entity\PageCategory;
1213
use Chamilo\CoreBundle\Entity\SequenceResource;
1314
use Chamilo\CoreBundle\Event\AbstractEvent;
1415
use Chamilo\CoreBundle\Event\AdminBlockDisplayedEvent;
1516
use Chamilo\CoreBundle\Event\Events;
17+
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
1618
use Chamilo\CoreBundle\Repository\PageCategoryRepository;
1719
use Chamilo\CoreBundle\Repository\PageRepository;
20+
use Chamilo\CoreBundle\Repository\PluginRepository;
1821
use Chamilo\CoreBundle\Settings\SettingsManager;
22+
use Plugin;
1923
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
2024
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2125
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -38,6 +42,8 @@ public function __construct(
3842
private readonly PageCategoryRepository $pageCategoryRepository,
3943
private readonly SerializerInterface $serializer,
4044
private readonly EventDispatcherInterface $eventDispatcher,
45+
private readonly PluginRepository $pluginRepository,
46+
private readonly AccessUrlHelper $accessUrlHelper,
4147
) {
4248
$this->extAuthSource = [
4349
'extldap' => [],
@@ -134,6 +140,12 @@ public function __invoke(): JsonResponse
134140
'items' => $this->getItemsChamilo(),
135141
'extraContent' => $this->getExtraContent('block-admin-chamilo'),
136142
];
143+
144+
$json['plugins'] = [
145+
'id' => 'block-admin-plugins',
146+
'editable' => false,
147+
'items' => $this->getItemsPlugins(),
148+
];
137149
}
138150

139151
/* Sessions */
@@ -861,4 +873,33 @@ private function getItemsSessions(): array
861873

862874
return $items;
863875
}
876+
877+
private function getItemsPlugins(): array
878+
{
879+
$items = [];
880+
881+
$accessUrl = $this->accessUrlHelper->getCurrent();
882+
$appPlugin = new AppPlugin();
883+
$plugins = $this->pluginRepository->getInstalledPlugins();
884+
885+
foreach ($plugins as $plugin) {
886+
$pluginInfo = $appPlugin->getPluginInfo($plugin->getTitle());
887+
/** @var Plugin $objPlugin */
888+
$objPlugin = $pluginInfo['obj'];
889+
$pluginInUrl = $plugin->getOrCreatePluginConfiguration($accessUrl);
890+
$configuration = $pluginInUrl->getConfiguration();
891+
892+
if (!in_array('menu_administrator', $configuration['regions'] ?? [])) {
893+
continue;
894+
}
895+
896+
$items[] = [
897+
'class' => 'item-plugin-'.$pluginInfo['title'],
898+
'url' => $objPlugin->getAdminUrl(),
899+
'label' => $pluginInfo['title'],
900+
];
901+
}
902+
903+
return $items;
904+
}
864905
}

0 commit comments

Comments
 (0)