New button triggering workflow

I tried to implement the functionality on my machine. I could get it successfully working. The following are the code changes:

  1. public\legacy\custom\Extension\application\Ext\Language\en_us.lang.php
<?php
$app_strings['LBL_ASSIGN_STATUS_CONFIRMATION']='Are you sure to change the status of this lead?';
  1. extensions\defaultExt\config\modules\Leads\recordview\actions\assign_lead.php
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\ContainerBuilder;

return static function (ContainerBuilder $container): void {


    $actions = $container->getParameter('module.recordview.actions') ?? [];
    $modules = $actions['modules'] ?? [];
    $leads = $modules['leads'] ?? [];
    $recordActions = $leads['actions'] ?? [];



    $recordActions['leads-assign'] = [
        'key' => 'leads-assign',
        'labelKey' => 'LBL_ASSIGN', 
        'asyncProcess' => 'true',
        'modes' => ['detail', 'edit'],
        'params' => [
			'displayConfirmation' => true, 
			'confirmationLabel' => 'LBL_ASSIGN_STATUS_CONFIRMATION',
			'module' => 'leads',
        ]
    ];


    $leads['actions'] = $recordActions;
    $modules['leads'] = $leads;
    $actions['modules'] = $modules;
    $container->setParameter('module.recordview.actions', $actions);
};
  1. extensions\defaultExt\modules\Leads\Process\Service\RecordActions\AssignLeadAction.php
<?php 

namespace App\Extension\defaultExt\modules\Leads\Process\Service\RecordActions;

use ApiPlatform\Exception\InvalidArgumentException;
use App\Engine\LegacyHandler\LegacyHandler;
use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;

class AssignLeadAction 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-leads-assign';
	
	private $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' => $leadsId] = $options;
		
         $this->init();


        $lead = \BeanFactory::getBean('Leads', $leadsId);



        if (empty($lead)) {
            $this->close();

            return [
                'status' => 'error',
                'data' => [],
                'messages' => [
                    'LBL_RECORD_NOT_FOUND'
                ]
            ];
        }


        $lead->status = 'Converted';

        $lead->save();


        $responseData = [
            'reload' => true,
        ];


        // Close legacy handler
        $this->close();

        $process->setStatus('success');
        $process->setMessages([]);
        $process->setData($responseData);	
		
		
    }
	
}
  1. Quick repair & rebuid and run the command: php bin/console cache:clear

image

It changed the status and reload the page to display the updated lead record.