Iâm trying to add a legacy view from SuiteCRM 7 to SuiteCRM 8.7 but encountering the following error: âYou are not authorized to view this page. Please contact your system administrator.â
In the legacy system, the view is mapped through the action_view_map.php file, located in the custom/application/ext/ActionViewMap folder. I have also created a class, MyRequiredAction, which extends LegacyHandler and implements ProcessHandlerInterface in SuiteCRM 8. Additionally, I updated the detailviewdefs.php file to include ârecordactionsâ, and I can see a new button displayed with the correct label (taken from Suite 7âs lang.php file).
However, when I click the button, I receive the ânot authorizedâ error message.
I followed a similar pattern as the convert-lead action in the Leads module. Has anyone successfully implemented a legacy view triggered by a button click from the Detail View page in SuiteCRM 8.7? Any help would be greatly appreciated. Thank you!
Hey @Harshad, the view you want to redirect to is a âclassicâ view, right? are you able to access it directly just by using the url on the browser?
Thanks for the reply. I donât want to display the classic view page. If you please go to leads module and check âConvert Leadâ button, the view I guess is âview.convertlead.phpâ from legacy/modules/leads/views. I am trying to display a custom view.myaction.php from my legacy/custom/modules/MyModule/views folder similar to the converlead functionality. Need to understand if this implementation is possible for custom pages(not popup) in v8.
I have successfully displayed a custom view from a legacy system in Suite8 by clicking a button. The URL is structured according to the new routing system.
Displaying a Custom View from SuiteCRM 7 in SuiteCRM 8
I wanted to share how to display a custom view from SuiteCRM 7 in the SuiteCRM 8 system. I referenced an article (and video) - SuiteCRM Developer Insights - Module Record Actions - SuiteCRM along with the code for âconvertleadâ action from the legacy âLeadsâ module to guide me through the process. Below are the steps I followed to successfully display a custom view:
The first step is to copy the detailviewdefs.php file from the modules/Accounts/metadata/ directory to the custom/modules/Accounts/metadata/ directory. This ensures that any changes you make are upgrade-safe.
After copying, add a new recordActions section in this file. You can define this action as follows:
To ensure that the custom button displays properly, you need to add a label for it in the language file. Create or update the following file if it doesnât already exist:
Add a new action view map by creating a file at the following path: custom/Extension/modules/Accounts/Ext/ActionViewMap/hello_world.php , and include the following code.
Create a new custom view by adding a file at the following path: custom/modules/Accounts/views/view.helloworld.php , and include the following content.
<?php
require_once('include/MVC/View/SugarView.php');
class CustomAccountsViewHelloworld extends SugarView{
public function __construct(){
parent::__construct();
}
public function display(){
echo 'Hello world';
}
}
Create a new RecordAction by adding a file at the following path: extensions/defaultExt/modules/Accounts/Process/Service/RecordActions/HelloWorldAction.php , and include the following content.
<?php
namespace App\Extension\defaultExt\modules\Accounts\Process\Service\RecordActions;
use ApiPlatform\Exception\InvalidArgumentException;
use App\Module\Service\ModuleNameMapperInterface;
use App\Engine\LegacyHandler\LegacyHandler;
use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;
class HelloWorldAction extends LegacyHandler implements ProcessHandlerInterface
{
protected const MSG_OPTIONS_NOT_FOUND = 'Process options are not defined';
protected const MSG_INVALID_TYPE = 'Invalid type';
public const PROCESS_TYPE = 'record-hello-world';
private $moduleNameMapper;
public function __construct(ModuleNameMapperInterface $moduleNameMapper)
{
$this->moduleNameMapper = $moduleNameMapper;
}
public function getProcessType(): string
{
return self::PROCESS_TYPE;
}
public function getHandlerKey(): string{
return $this->getProcessType();
}
public function configure(Process $process): void
{
$process->setId(self::PROCESS_TYPE);
$process->setAsync(false);
}
public function requiredAuthRole(): string
{
return 'ROLE_USER';
}
public function getRequiredACLs(Process $process): array
{
$options = $process->getOptions();
$module = $options['module'] ?? '';
$id = $options['id'] ?? '';
return [
$module => [
[
'action' => 'view',
'record' => $id
],
],
];
}
public function validate(Process $process): void
{
if (empty($process->getOptions())) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
$options = $process->getOptions();
if (empty($options['module']) || empty($options['action'])) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
if (empty($options['id'])) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
}
public function run(Process $process)
{
$options = $process->getOptions();
['id' => $accountId] = $options;
$responseData = [
'handler' => 'redirect',
'params' => [
'route' =>$options['module'] . '/hello-world/' .$accountId,
'queryParams' => [
]
]
];
$process->setStatus('success');
$process->setMessages([]);
$process->setData($responseData);
}
}
Run Quick Repair & Rebuild , then visit the page by clicking the âHello Worldâ button.