How to create a customer config file for a Service and make editable for a Pimcore Admin User

25 Views Asked by At

My Requirements:

Pimcore 11

I need a dynamic config file for a Service Class:

// the config file (myCustomerServiceConfig.yaml)

keysAllias:  
    key1: 'import_key_1'
    key2: 'import_key_2'
    key3: 'import_key_3'
    key4: 'import_key_4'

customersparts:
    routes:
        route1:
            routeId: 'route1'
            keys: 'key1, key2, key3'        
      route2:
            routeId: 'route2'
            keys: 'key2, key3'        
      route3:
            routeId: 'route3'
            keys: 'key1, key4'

I need a Service class (MyCustomerService.class.php) and i want to use the configuration file from above inside the Service

class MyCustomerService

{
    private myCustomerServiceConfig $customerConfig;
    private array $configResults;

    public function setCustomerRouteConfig (array $configValues) : array
    {
        $this->configResults = [];
        foreach ($this->customerConfig['keysAllias'] as $k => $V) 
        {
            if (isset($configValues[$v])) {
                $this->configResults[$k] = $configValues[$v];
            }
        }
    }

    public function getCustomerRouteConfig (string $routeId) : array
    {
        $this->routeConfig = [];
        $this->configRouteKeys = $this->customerConfig['customersparts']['routes'][$routeId]['keys'] ?? NULL;

        if ($this->configRouteKeys === NULL) {
            return $this->routeConfig;
        }
        
        foreach ($this->configRouteKeys as $k) 
        {
            if (isset($this->configResults[$k])) {
                $this->routeConfig[$k] = $this->configResults[$k];
            }
        }

        return $this->configResults;
    }
}

I use a Controller (CustomerController.php)

use MyCustomerService;

class CustomerController
{
    private array $routeConfig;

    __construct () 
    {
        MyCustomerService->setCustomerRouteConfig([
            'import_key_1' => 'some values',
            'import_key_2' => 'some values',
            'import_key_3' => 'some values',
            'import_key_4' => 'some values',
        ]);

        $this->routeConfig = MyCustomerService->getCustomerRouteConfig('route1');
    }
}

I have two Questions:

1.) How i can implement the myCustomerServiceConfig.yaml,so i can use it in MyCustomerService?

2.) How can create a admin page in Pimcore, where a admin-user can edit the myCustomerServiceConfig.yaml?

0

There are 0 best solutions below