mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 04:21:06 +08:00
Add user action menu legacy handler
This commit is contained in:
parent
8338cae4d1
commit
471adea58e
6 changed files with 228 additions and 18 deletions
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace SuiteCRM\Core\Legacy;
|
||||
|
||||
use DoctrineTest\InstantiatorTestAsset\ExceptionAsset;
|
||||
|
||||
/**
|
||||
* Class LegacyHandler
|
||||
* @package SuiteCRM\Core\Legacy
|
||||
|
@ -17,22 +15,24 @@ class LegacyHandler
|
|||
*/
|
||||
public function runLegacyEntryPoint(): bool
|
||||
{
|
||||
if ($this->config !== null) {
|
||||
// Set up sugarEntry
|
||||
if (!defined('sugarEntry')) {
|
||||
define('sugarEntry', true);
|
||||
}
|
||||
|
||||
// Set working directory for legacy
|
||||
chdir(BASE_PATH . '/legacy');
|
||||
|
||||
// Load in legacy
|
||||
require_once 'include/MVC/preDispatch.php';
|
||||
require_once 'include/entryPoint.php';
|
||||
|
||||
return true;
|
||||
if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2) . '/');
|
||||
}
|
||||
|
||||
return false;
|
||||
// Set up sugarEntry
|
||||
if (!defined('sugarEntry')) {
|
||||
define('sugarEntry', true);
|
||||
}
|
||||
|
||||
$legacyPath = realpath(BASE_PATH . '/legacy');
|
||||
|
||||
// Set working directory for legacy
|
||||
chdir($legacyPath);
|
||||
|
||||
// Load in legacy
|
||||
require_once 'include/MVC/preDispatch.php';
|
||||
require_once 'include/entryPoint.php';
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
80
core/legacy/Navbar.php
Normal file
80
core/legacy/Navbar.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace SuiteCRM\Core\Legacy;
|
||||
|
||||
/**
|
||||
* Class Navbar
|
||||
* @package SuiteCRM\Core\Legacy
|
||||
*/
|
||||
class Navbar extends LegacyHandler
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUserActionMenu(): array
|
||||
{
|
||||
if ($this->runLegacyEntryPoint()) {
|
||||
$userActionMenu = [];
|
||||
$global_control_links = [];
|
||||
$last = [];
|
||||
|
||||
$userActionMenu[] = [
|
||||
'label' => 'Profile',
|
||||
'url' => 'index.php?module=Users&action=EditView&record=1',
|
||||
'submenu' => [],
|
||||
];
|
||||
|
||||
require 'include/globalControlLinks.php';
|
||||
|
||||
foreach ($global_control_links as $key => $value) {
|
||||
if ($key === 'users') {
|
||||
$last[] = [
|
||||
'label' => key($value['linkinfo']),
|
||||
'url' => $value['linkinfo'][key($value['linkinfo'])],
|
||||
'submenu' => [],
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($value as $linkAttribute => $attributeValue) {
|
||||
// get the main link info
|
||||
if ($linkAttribute === 'linkinfo') {
|
||||
$userActionMenu[] = [
|
||||
'label' => key($attributeValue),
|
||||
'url' => current($attributeValue),
|
||||
'submenu' => [],
|
||||
];
|
||||
|
||||
$userActionMenuCount = count($userActionMenu);
|
||||
$key = $userActionMenuCount - 1;
|
||||
|
||||
if (strpos($userActionMenu[$key]['url'], 'javascript:') === 0) {
|
||||
$userActionMenu[$key]['event']['onClick'] = substr($userActionMenu[$key]['url'], 11);
|
||||
$userActionMenu[$key]['url'] = 'javascript:void(0)';
|
||||
}
|
||||
}
|
||||
// Get the sub links
|
||||
if ($linkAttribute === 'submenu' && is_array($attributeValue)) {
|
||||
$subMenuLinkKey = '';
|
||||
foreach ($attributeValue as $submenuLinkKey => $submenuLinkInfo) {
|
||||
$userActionMenu[$key]['submenu'][$submenuLinkKey] = [
|
||||
'label' => key($submenuLinkInfo),
|
||||
'url' => current($submenuLinkInfo),
|
||||
];
|
||||
}
|
||||
if (strpos($userActionMenu[$key]['submenu'][$subMenuLinkKey]['url'], 'javascript:') === 0) {
|
||||
$userActionMenu[$key]['submenu'][$subMenuLinkKey]['event']['onClick'] =
|
||||
substr($userActionMenu[$key]['submenu'][$subMenuLinkKey]['url'], 11);
|
||||
$userActionMenu[$key]['submenu'][$subMenuLinkKey]['url'] = 'javascript:void(0)';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $userActionMenu[] = array_merge($userActionMenu, $last);
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Running legacy entry point failed');
|
||||
}
|
||||
}
|
36
core/legacy/NavbarService.php
Normal file
36
core/legacy/NavbarService.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace SuiteCRM\Core\Legacy;
|
||||
|
||||
use SuiteCRM\Core\Base\Module\Service\ServiceFactoryInterface;
|
||||
|
||||
/**
|
||||
* Class NavbarService
|
||||
* @package SuiteCRM\Core\Legacy
|
||||
*/
|
||||
class NavbarService implements ServiceFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'template.navbar';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'This service will deal with retrieval of the navbar structure';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function createService()
|
||||
{
|
||||
return new Navbar();
|
||||
}
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
php "$PWD"/../../vendor/bin/phpunit --coverage-html coverage/html $@
|
||||
php "$PWD"/../../vendor/bin/phpunit $@;
|
||||
|
|
36
core/tests/unit/phpunit/legacy/NavbarServiceTest.php
Normal file
36
core/tests/unit/phpunit/legacy/NavbarServiceTest.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SuiteCRM\Core\Legacy\Navbar;
|
||||
use SuiteCRM\Core\Legacy\NavbarService;
|
||||
|
||||
final class NavbarServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var NavbarService
|
||||
*/
|
||||
private $navbarService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->navbarService = new NavbarService();
|
||||
}
|
||||
|
||||
public function testGetName(): void
|
||||
{
|
||||
$this->assertSame('template.navbar', $this->navbarService->getName());
|
||||
}
|
||||
|
||||
public function testGetDescription(): void
|
||||
{
|
||||
$this->assertSame('This service will deal with retrieval of the navbar structure', $this->navbarService->getDescription());
|
||||
}
|
||||
|
||||
public function testCreateService(): void
|
||||
{
|
||||
$this->assertInstanceOf(Navbar::class, $this->navbarService->createService());
|
||||
}
|
||||
}
|
||||
|
||||
|
58
core/tests/unit/phpunit/legacy/NavbarTest.php
Normal file
58
core/tests/unit/phpunit/legacy/NavbarTest.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SuiteCRM\Core\Legacy\Navbar;
|
||||
|
||||
final class NavbarTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Navbar
|
||||
*/
|
||||
private $navbar;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->navbar = new Navbar();
|
||||
}
|
||||
|
||||
public function testGetUserActionMenu(): void
|
||||
{
|
||||
$expected = [
|
||||
0 => [
|
||||
'label' => 'Profile',
|
||||
'url' => 'index.php?module=Users&action=EditView&record=1',
|
||||
'submenu' => []
|
||||
],
|
||||
1 => [
|
||||
'label' => 'Employees',
|
||||
'url' => 'index.php?module=Employees&action=index',
|
||||
'submenu' => []
|
||||
],
|
||||
2 => [
|
||||
'label' => 'Support Forum',
|
||||
'url' => 'javascript:void(0)',
|
||||
'submenu' => [],
|
||||
'event' => [
|
||||
'onClick' => "void(window.open('https://suitecrm.com/suitecrm/forum/suite-forum'))"
|
||||
]
|
||||
],
|
||||
3 => [
|
||||
'label' => 'About',
|
||||
'url' => 'index.php?module=Home&action=About',
|
||||
'submenu' => []
|
||||
],
|
||||
4 => [
|
||||
'label' => 'Logout',
|
||||
'url' => 'index.php?module=Users&action=Logout',
|
||||
'submenu' => []
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->navbar->getUserActionMenu()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue