|
3 | 3 | /** |
4 | 4 | * This file is part of MetaModels/core. |
5 | 5 | * |
6 | | - * (c) 2012-2015 The MetaModels team. |
| 6 | + * (c) 2012-2017 The MetaModels team. |
7 | 7 | * |
8 | 8 | * For the full copyright and license information, please view the LICENSE |
9 | 9 | * file that was distributed with this source code. |
|
14 | 14 | * @subpackage Core |
15 | 15 | * @author Christian Schiffler <c.schiffler@cyberspectrum.de> |
16 | 16 | * @author Cliff Parnitzky <github@cliff-parnitzky.de> |
| 17 | + * @author Sven Baumann <baumann.sv@gmail.com> |
17 | 18 | * @copyright 2012-2017 The MetaModels team. |
18 | 19 | * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0 |
19 | 20 | * @filesource |
@@ -357,7 +358,7 @@ public function buildMandatoryWidget(BuildWidgetEvent $event) |
357 | 358 | } |
358 | 359 |
|
359 | 360 | $model = $event->getModel(); |
360 | | - $metaModel = $this->getMetaModelById($model->getProperty('pid')); |
| 361 | + $metaModel = $this->getMetaModelById($this->getMetaModelId($event)); |
361 | 362 |
|
362 | 363 | if ($metaModel->getAttributeById($model->getProperty('attr_id'))->get('isunique')) { |
363 | 364 | Message::addInfo( |
@@ -617,4 +618,44 @@ public function buildPaletteRestrictions(BuildDataDefinitionEvent $event) |
617 | 618 | } |
618 | 619 | } |
619 | 620 | } |
| 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 | + } |
620 | 661 | } |
0 commit comments