Skip to main content
Version: Next

Extending Adapters

The bundle ships adapters for the standard data types, plus specialized ones such as objectbrick that keep only specific fields. Override the shipped backend adapters (for example input or numeric) with your own classes, and map additional data types when needed.

The configuration is a key-value map in your config/config.yaml file under the key pimcore_backend_power_tools.pimcore_alternative_object_trees.adapters. Each entry pairs one of the four built-in frontend adapters with a backend adapter class:

pimcore_backend_power_tools:
pimcore_alternative_object_trees:
adapters:
input:
frontend: SimpleValueAdapter
backend: App\Adapter\AlternativeElementTree\CustomValueAdapter #= the custom backend adapter
custom:
frontend: SimpleValueAdapter #= must be one of the four built-in frontend adapters
backend: Pimcore\Bundle\BackendPowerToolsBundle\Adapter\AlternativeElementTree\DataObject\SimpleValueAdapter

The frontend key only selects which controls the Tree Levels tab renders. It cannot name a class of your own, see Frontend Adapters. All custom logic belongs in the backend adapter.

Extend a Shipped Adapter​

The shipped backend adapters in Pimcore\Bundle\BackendPowerToolsBundle\Adapter\AlternativeElementTree\DataObject are not final, so you can extend one instead of copying it and change only what differs. For example, to show a custom value for input fields. The example only changes what the tree shows, so it also turns off value assignment; otherwise a drag and drop into a folder would write the changed text back into the object:

<?php

namespace App\Adapter\AlternativeElementTree;

use Pimcore\Bundle\BackendPowerToolsBundle\Adapter\AlternativeElementTree\DataObject\SimpleValueAdapter;

class CustomValueAdapter extends SimpleValueAdapter
{
// the displayed value differs from the stored one, so never write it back
public function supportsValueAssignment(): bool
{
return false;
}

protected function getAdapterValues(): array
{
return array_map(
static fn (mixed $value) => is_string($value) ? mb_strtoupper($value) : $value,
parent::getAdapterValues()
);
}
}

Register the class as a service tagged pimcore.backend_power_tools.alternative_element_trees.data_object.adapter (the tag the shipped adapters use) and map it under adapters.<type>.backend as shown above. Re-inject the constructor arguments of the parent class when you override the constructor.

The adapters are marked @internal: you can extend them, but at your own risk, as their protected members may change in minor releases. Private services (for example the translator in CheckboxAdapter) are not reachable from a subclass; inject them again if you need them.