Hello,
I have added the custom button into the Contacts module. However when I am click on it, SuiteCRM gives an error âUnexpected error when calling actionâ. I have checked the console log an it says the âInternal server errorâ.
I have added the code as follows for my custom button.
[1] custom/modules/Contacts/metadata/detailviewdefs.php
'add-custom-button' =>
array (
'key' => 'add-custom-button',
'labelKey' => 'LBL_ADD_CUSTOM_BUTTON',
'asyncProcess' => true,
'modes' =>
array (
0 => 'detail',
),
'acl' =>
array (
0 => 'view',
),
),
[2] extensions/cstmButton/modules/Contacts/Service/AddCustomButton.php
namespace App\Extension\cstmButton\modules\Contacts\Service;
namespace App\Process\Service\RecordActions;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Process\Entity\Process;
use App\Module\Service\ModuleNameMapperInterface;
use App\Process\Service\ProcessHandlerInterface;
class AddCustomButton implements ProcessHandlerInterface
{
protected const MSG_OPTIONS_NOT_FOUND = âProcess options is not definedâ;
protected const PROCESS_TYPE = âadd-custom-buttonâ;
/**
* @var ModuleNameMapperInterface
*/
private $moduleNameMapper;
/**
* PrintAsPdfAction constructor.
* @param ModuleNameMapperInterface $moduleNameMapper
*/
public function __construct(ModuleNameMapperInterface $moduleNameMapper)
{
$this->moduleNameMapper = $moduleNameMapper;
}
/**
* @inheritDoc
*/
public function getProcessType(): string
{
return self::PROCESS_TYPE;
}
/**
* @inheritDoc
*/
public function requiredAuthRole(): string
{
return 'ROLE_USER';
}
/**
* @inheritDoc
*/
public function configure(Process $process): void
{
//This process is synchronous
//We aren't going to store a record on db
//thus we will use process type as the id
$process->setId(self::PROCESS_TYPE);
$process->setAsync(false);
}
/**
* @inheritDoc
*
*/
public function validate(Process $process): void
{
if (empty($process->getOptions())) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
$options = $process->getOptions();
[
'module' => $baseModule,
'id' => $id
] = $options;
['modalRecord' => $modalRecord] = $options['params'];
[
'module' => $modalModule,
'id' => $modalId
] = $modalRecord;
if (empty($baseModule) || empty($id) || empty($modalModule) || empty($modalId)) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
}
/**
* @inheritDoc
*/
public function run(Process $process)
{
$GLOBALS['log']->fatal(" Comes into custom button run");
$process->setStatus('success');
$process->setMessages([]);
$process->setData($responseData);
}
}
[3] Following is the error screenshot.
[4] While clearing the cache from command > php ./bin/console cache:clear
I am getting the following error.
Expected to find class âApp\Extension\cstmButton\modules\Contacts\Service\AddCustomButtonâ in file âextensions/cstmButton\modules\Contacts\Service\AddCustomButton.phpâ while importing services from resource ââŚ/extensions/*â, but it was not found! Check the names pace prefix used with the resource in config\core_services.yaml (which is being imported from âconfig/services.yamlâ).
Am I missing something to work it? Is there any build process or something remaining to working this button?
Thanks.