Backend Calculation - get Value from other Module

Hey @dwaltsch,

The problem here is due to the way you are loading LegacyCompany within SearchCompany.

Since you are doing new LegacyCompany() the dependencies that are required for the LegacyHandler aren’t injected. (See LegacyHandler class constructor). When using dependency injection the constructor dependencies are automatically injected.

When using symfony you should use dependency injection and the container as much as possible.

I personally try to avoid instantiating new classes using new SomeClass() as much as possible. With that you loose all the benefits of using dependency injection and the container.

<?php

namespace App\Extension\eks\modules\eks_maintenance\Service\Fields;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Extension\eks\modules\eks_maintenance\Service\Fields\Legacy\LegacyCompany;
use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;
use BeanFactory;
use SugarBean;
use Sugarcrm\Util\LoggerManager;


class SearchCompany implements ProcessHandlerInterface
{
    protected const MSG_OPTIONS_NOT_FOUND = 'Process options are not defined';
    public const PROCESS_TYPE = 'search_company';
    
    /**
     * @var LegacyCompany
     */
    protected $legacyCompany;

    public function __construct(LegacyCompany $legacyCompany)
    {
        $this->legacyCompany = $legacyCompany;
    }
    public function getProcessType(): string
    {
        return self::PROCESS_TYPE;
    }

    public function requiredAuthRole(): string
    {
        return '';
    }

    public function getRequiredACLs(Process $process): array
    {
        return [];
    }

    public function configure(Process $process): void
    {
        $process->setId(self::PROCESS_TYPE);
        $process->setAsync(false);
    }

    public function validate(Process $process): void
    {
    }

    public function getCompany($itemid) {
        return $this->legacyCompany->getLegacyCompany($itemid);
    }
    public function run(Process $process)
    {
        $options = $process->getOptions();
        $record = $options['record'];
        $attributes = $record['attributes'];
        $value = $attributes['eks_project_position_eks_maintenance_1_name']['name'];
        $maintenanceid = $attributes['eks_project_position_eks_maintenance_1_name']['id'];
        $company = $this->getCompany($maintenanceid);
        $responseData = [
            'value' => $value
        ];

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

(PS: I did the changes on the code directly here, there could be an import missing or something)

By the way, I agree with @pgr it could be easier to just extends LegacyHandler implements ProcessHandlerInterface in SearchCompany