SuiteCRM 8 Extensions

Hi @sfleming,

Welcome to the community :wave: and thanks for trying out SuiteCRM 8.

I’m not sure if it was just a problem of the copy. But it seems that the following file has 2 namespaces defined.
extensions/cstmButton/modules/Contacts/Service/AddCustomButton.php

From what you posted:

namespace App\Extension\cstmButton\modules\Contacts\Service;
namespace App\Process\Service\RecordActions; 

Try removing namespace App\Process\Service\RecordActions; . (It may lead to missing imports, so please check if all required imports use are added)

Hope this helps

Hello,

I have tried with the commenting a line you have mentioned and still getting the same error into the SuiteCRM.(Unexpected error when calling action + Internal Server Error)

Previously it gives me following error while clearing the cache from the cli.

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”).

Now that error is resolved but I am not able to get the button working.

Am I still missing something to work it?

Thanks.

Hi @sfleming,

Had another look at the code, I think you need to add the record- prefix to the process type on the AddCustomButtom class.

So, you need to replace the following:

protected const PROCESS_TYPE = ‘add-custom-button’;

With
protected const PROCESS_TYPE = ‘record-add-custom-button’;

Hello,

I have tried with the record-add-custom-button but still it gives the same error. Also I am trying to add the logger as you have mentioned into earlier post. However, when I am adding the following 2 lines then Contacts record is not loaded, ListView is not loaded and CRM redirects to the Home screen.

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;

Can I have perform some build or something to make it working? If yes then from where I can have to do it?

Thanks.

Hi @sfleming,

Could you send me your current version of AddCustomButton.php please? I makes it easier to check what the problem might be

Regarding the build. After doing these changes you should have to run ./bin/console cache:clear

Hello,

Finally I got it working. Following statement is created the problem and I am getting Internal Server Error. I have commented that line and now it is working well.

$this->logger->fatal(“Test into run”);

I want to check whether button click is coming into the run function or not. That’s why I have added fatal log.

Following is the final code into AddCustomButton.php file

namespace App\Extension\cstmButton\modules\Contacts\Service;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Process\Entity\Process;
use App\Module\Service\ModuleNameMapperInterface;
use App\Process\Service\ProcessHandlerInterface;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;

class AddCustomButton implements ProcessHandlerInterface, LoggerAwareInterface
{
    protected const MSG_OPTIONS_NOT_FOUND = 'Process options is not defined';
    protected const PROCESS_TYPE = 'record-add-custom-button';

    /**
     * @var ModuleNameMapperInterface
     */
    private $moduleNameMapper;
    
    /**
     * @var LoggerInterface
     */
    protected $logger;

    /**
     * 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
    {
        
    }
    

    /**
     * @inheritDoc
     */
    public function run(Process $process)
    {
        $process->setStatus('success');
        $process->setMessages([]);
        $process->setData($responseData);
        
        
    }
        
    /**
     * @inheritDoc
     */
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
}

Thanks.

Hi @sfleming,

Great, I’m glad you were able to solve it!

Hello,

Thanks for all the guidance in this thread to add the custom button. I need help to redirect the create screen after clicked on the custom button added previously. Before redirect I want to show the modal same as Delete button to ask Are you sure to redirect on create?

I have checked the config/services/module/recordview/actions.yaml file where the Delete button code is written.

Can you guide me how the JS click event is handling and how to achieve the redirection?

Thanks.

Hi @sfleming,

Yes, what you can do is the following

1. Request confirmation

On the button configuration add a params entry with displayConfirmation set to true. Also define the label you want to display in confirmationLabel.
Something like:

                '<your-action>' => [
                    ....
                    'asyncProcess' => true,
                    'params' => [
                        ....
                        'displayConfirmation' => true,
                        'confirmationLabel' => 'NTC_DELETE_CONFIRMATION'
                    ],
                    ....
                ],

2. Set a redirect action handler.

On your backend process handler (the AddCustomButtom class, or whatever you want to call it). You can defined on the response a frontend handler. The handler is going to be called on the frontend after the response from the backend.

There is redirect handler that you can call, the only thing you need is to pass the route` to redirect to.

Something like:

    /**
     * @inheritDoc
     */
    public function run(Process $process)
    {
        $options = $process->getOptions();
        $module =  $options['module']; // or "your-module"
        
        $responseData = [
            'handler' => 'redirect',
            'params' => [
                'route' => "$module/create",
                'queryParams' => [
                ]
            ]
        ];

        $process->setStatus('success');
        $process->setMessages([]);
        $process->setData($responseData);
    }

Hope this helps

Hello,

Thanks for the reply, I have successfully redirect on the create action. However, I am not getting the conformation dialog. Following is the code for my button definition.

'add-custom-button' => 
array (
  'key' => 'add-custom-button',
  'labelKey' => 'LBL_ADD_CUSTOM_BUTTON',
  'asyncProcess' => true,
  'modes' => 
  array (
	0 => 'detail',
  ),
  'acl' => 
  array (
	0 => 'view',
  ),
  'params' => 
  array (
	'selectModal' => 
	array (
	  'displayConfirmation' => true,
	  'confirmationLabel' => 'NTC_DELETE_CONFIRMATION'
	),
  ),
),

Also, while redirection I need to send some information like name, id etc… I need to send those information as a POST and not into the query string as shown below.

http://localhost/suitecrm800/public/#/opportunities/edit?contact_name=Marcellus Welcome&contact_id=10a766c5-4ee6-941d-6936-61bc87c2ddfc

Following is the code into my AddCustomButton.php file

/**
 * @inheritDoc
 */
public function run(Process $process)
{   
    $options = $process->getOptions();
    $module =  "Opportunities"; //$options['module'] or "your-module"
    
    $responseData = [
        'handler' => 'redirect',
        'params' => [
            'route' => "$module/edit",
            'queryParams' => [
                'contact_name' => 'Marcellus Welcome',
                'contact_id' => '10a766c5-4ee6-941d-6936-61bc87c2ddfc',
            ]
        ]
    ];
    
    $process->setStatus('success');
    $process->setMessages([]);
    $process->setData($responseData);
}

Thanks.

Hi @sfleming,

Sorry for the delay in replying.

Regarding question on your last post.

Confirmation modal

I think the modal is not showing because the definition is under selectModal. It should be directly under params:

    'params' => [
        'displayConfirmation' => true,
        'confirmationLabel' => 'NTC_DELETE_CONFIRMATION'
     ],

Post redirection

Post redirection is not supported. If you want to do something similar, you could pre-create and save the new record on the backend call, and then re-direct the user to the new record.

The alternative is to send the fields in a Get redirect as query params

Hello,

Thanks for the answer. The conformation modal has been display well after put it under params.

Now instead of display conformation dialog, Is it possible to display custom modal on the button click event? The modal contains some dropdown/textbox and button. The redirection will happens once anyone change the dropdown or click the button.

Hi @sfleming,

Sorry for the delay in replying. To do that you need to setup the front end development environment and create a front end extension. It is not easy to do and the documentation for the extension framework for doing it hasn’t been finished yet.

Hello,

Thanks for all the guidance in this thread to add the custom button.

I am trying to export the records of a list view via an entry point by creating a custom button similar to the default export button. But I get the same problem every time.

image

So how can I solve it?

Thanks.

syntax error, unexpected ‘default’ (T_DEFAULT), expecting identifier (T_STR
ING)
please help me

Hello,

I have installed SuiteCRM 8.3.0 and created a frontend extension successfully and now I can see the message on the console which I print on my extension.
I have created custom button also but now I want to trigger an action or call a javascript function on custom action button onclick.

Can anyone suggest me, how to call js function on custom action button in SuiteCRM 8 ?

Thanks