Skip to content

Commit 191db54

Browse files
committed
Merge pull request #1106 - get correct MetaModel
The property "pid" reference in dca settings refers to to dca config. So we have to go one reference higher to obtain the MetaModel.
2 parents 9579ebb + 2bdc405 commit 191db54

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

contao/dca/tl_metamodel_dcasetting.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @author Stefan Heimes <stefan_heimes@hotmail.com>
2121
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
2222
* @author Cliff Parnitzky <github@cliff-parnitzky.de>
23+
* @author Sven Baumann <baumann.sv@gmail.com>
2324
* @copyright 2012-2017 The MetaModels team.
2425
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0
2526
* @filesource
@@ -77,6 +78,15 @@
7778
),
7879
),
7980
'filter' => array
81+
(
82+
array
83+
(
84+
'local' => 'pid',
85+
'remote' => 'id',
86+
'operation' => '=',
87+
),
88+
),
89+
'inverse' => array
8090
(
8191
array
8292
(

src/MetaModels/DcGeneral/Events/Table/InputScreens/Subscriber.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/core.
55
*
6-
* (c) 2012-2015 The MetaModels team.
6+
* (c) 2012-2017 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -14,6 +14,7 @@
1414
* @subpackage Core
1515
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
1616
* @author Cliff Parnitzky <github@cliff-parnitzky.de>
17+
* @author Sven Baumann <baumann.sv@gmail.com>
1718
* @copyright 2012-2017 The MetaModels team.
1819
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0
1920
* @filesource
@@ -357,7 +358,7 @@ public function buildMandatoryWidget(BuildWidgetEvent $event)
357358
}
358359

359360
$model = $event->getModel();
360-
$metaModel = $this->getMetaModelById($model->getProperty('pid'));
361+
$metaModel = $this->getMetaModelById($this->getMetaModelId($event));
361362

362363
if ($metaModel->getAttributeById($model->getProperty('attr_id'))->get('isunique')) {
363364
Message::addInfo(
@@ -617,4 +618,44 @@ public function buildPaletteRestrictions(BuildDataDefinitionEvent $event)
617618
}
618619
}
619620
}
621+
622+
/**
623+
* Get the id from the meta model.
624+
*
625+
* @param BuildWidgetEvent $event The event.
626+
*
627+
* @return string
628+
*/
629+
protected function getMetaModelId(BuildWidgetEvent $event)
630+
{
631+
$environment = $event->getEnvironment();
632+
$dataDefinition = $environment->getDataDefinition();
633+
$parentDataDefinition = $environment->getParentDataDefinition();
634+
$parentDataProvider = $environment->getDataProvider($parentDataDefinition->getName());
635+
$relationship = $dataDefinition->getModelRelationshipDefinition();
636+
$parentRelationship = $parentDataDefinition->getModelRelationshipDefinition();
637+
638+
$childCondition =
639+
$relationship->getChildCondition($parentDataDefinition->getName(), $dataDefinition->getName());
640+
641+
$parentModel = $parentDataProvider->fetch(
642+
$parentDataProvider->getEmptyConfig()
643+
->setFilter($childCondition->getInverseFilterFor($event->getModel()))
644+
);
645+
646+
$metaModelDataProvider =
647+
$environment->getDataProvider($parentDataDefinition->getBasicDefinition()->getParentDataProvider());
648+
649+
$parentChildCondition = $parentRelationship->getChildCondition(
650+
$parentDataDefinition->getBasicDefinition()->getParentDataProvider(),
651+
$parentDataDefinition->getName()
652+
);
653+
654+
$metaModel = $metaModelDataProvider->fetch(
655+
$metaModelDataProvider->getEmptyConfig()
656+
->setFilter($parentChildCondition->getInverseFilterFor($parentModel))
657+
);
658+
659+
return $metaModel->getId();
660+
}
620661
}

0 commit comments

Comments
 (0)