DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Persistence service

This service will handle all the persistence related-features, meaning it will allow configuration objects to have domain objects attributes (for instance TYPO3\CMS\Extbase\Domain\Model\FrontendUser or TYPO3\CMS\Extbase\Domain\Model\Category). Basically, every property which is typed as a class which implements the interface TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface will be handled correctly.

It means you can fill a configuration array with identifiers (generally the value of uid), and the API will automatically fetch the correct domain object during the conversion of the configuration object. Look below for a working example.

Note

This service can be used when the Cache service is activated, it will always fetch an updated version of the domain objects, and not put them directly in cache.

Usage

You can activate this service for a given configuration object by attaching it to the ServiceFactory in the static function getConfigurationObjectServices(). Use the constant ServiceInterface::SERVICE_PERSISTENCE as an identifier for this service (see example below).

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use Romm\ConfigurationObject\Service\ServiceInterface;
use Romm\ConfigurationObject\Service\ServiceFactory;
use Romm\ConfigurationObject\ConfigurationObjectInterface;
use Romm\ConfigurationObject\Traits\ConfigurationObject\DefaultConfigurationObjectTrait;
use Romm\ConfigurationObject\Traits\ConfigurationObject\MagicMethodsTrait;

class Company implements ConfigurationObjectInterface
{
    use DefaultConfigurationObjectTrait;
    use MagicMethodsTrait;

    /**
     * @var \TYPO3\CMS\Beuser\Domain\Model\BackendUser
     */
    protected $boss;

    /**
     * @var \TYPO3\CMS\Beuser\Domain\Model\BackendUser[]
     */
    protected $employees;

    /**
     * @return ServiceFactory
     */
    public static function getConfigurationObjectServices()
    {
        return ServiceFactory::getInstance()
            ->attach(ServiceInterface::SERVICE_PERSISTENCE);
    }
}

$companyConfigurationArray = [
    // Identifier of the `backend_users` record for the boss user account.
    'boss'      => 1,
    'employees' => [
        // Identifiers of the `backend_users` records for every employee.
        'john.doe' => 2,
        'jane.doe' => 3
    ]
];

$myCompany = ConfigurationObjectFactory::convert(
    Company::class,
    $companyConfigurationArray
);