Layout Inheritance #17033
Unanswered
cancan101
asked this question in
Q&A / Support
Layout Inheritance
#17033
Replies: 1 comment
-
It is not possible to create inherited custom layouts. If you just would like to change the Here a very fast example which sets the <?php
declare(strict_types=1);
namespace App\EventSubscriber;
use Closure;
use Pimcore\Bundle\AdminBundle\Event\AdminEvents;
use Pimcore\Model\DataObject\ClassDefinition;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class PreSendDataSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
AdminEvents::OBJECT_GET_PRE_SEND_DATA => 'onObjectGetPreSendData',
];
}
public function onObjectGetPreSendData(GenericEvent $event)
{
$data = $event->getArguments()['data'];
if($data['currentLayoutId'] ?? null == '0') {
$this->enrichLayoutDefinition($data['layout'], function($node) {
if($node instanceof ClassDefinition\Data\Input && $node->getName() == 'name') {
$node->setNoteditable(true);
}
});
}
}
private function enrichLayoutDefinition(ClassDefinition\Data|ClassDefinition\Layout|null &$layout, Closure $modifyNodeFunction): void
{
if($layout === null || !method_exists($layout, 'getChildren')) {
return;
}
foreach ($layout->getChildren() ?? [] as $node) {
$modifyNodeFunction($node);
$this->enrichLayoutDefinition($node, $modifyNodeFunction);
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there any concept of layout inheritance for custom layouts such that I don't have to copy and paste the entire base class definition if I want to modify a small number of fields in the custom layout?
For example if I want to just change the fields to read only, do I need to copy and paste the entire class definition but change
noteditable
to true? or is there a cleaner way to maintain this? Asking because right now keeping all of the layouts in sync is problematic as new fields are added.Beta Was this translation helpful? Give feedback.
All reactions