Skip to content

Commit bd9e359

Browse files
committed
Merge pull request #1087 - add getVariantBase()
This implements feature request #237 by adding the requested method: `IItem::getVariantBase()`.
2 parents 191db54 + 6ef3a24 commit bd9e359

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/MetaModels/IItem.php

Lines changed: 13 additions & 3 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,7 +14,8 @@
1414
* @subpackage Core
1515
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
1616
* @author Stefan Heimes <stefan_heimes@hotmail.com>
17-
* @copyright 2012-2015 The MetaModels team.
17+
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
18+
* @copyright 2012-2017 The MetaModels team.
1819
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0
1920
* @filesource
2021
*/
@@ -107,10 +108,19 @@ public function isVariantBase();
107108
*
108109
* @param \MetaModels\Filter\IFilter $objFilter The filter settings to be applied.
109110
*
110-
* @return \MetaModels\IItems A list of all variants for this item.
111+
* @return \MetaModels\IItems|null A list of all variants for this item or null if the item cannot handle variants.
111112
*/
112113
public function getVariants($objFilter);
113114

115+
/**
116+
* Fetch the meta model variant base for this item.
117+
*
118+
* Note: For a non-variant item the variant base is the item itself.
119+
*
120+
* @return IItem The variant base.
121+
*/
122+
public function getVariantBase();
123+
114124
/**
115125
* Save the current data for every attribute to the data sink.
116126
*

src/MetaModels/Item.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function isVariantBase()
285285
*
286286
* @param IFilter $objFilter The filter settings to be applied.
287287
*
288-
* @return IItems A list of all variants for this item.
288+
* @return IItems|null A list of all variants for this item.
289289
*/
290290
public function getVariants($objFilter)
291291
{
@@ -296,6 +296,22 @@ public function getVariants($objFilter)
296296
return null;
297297
}
298298

299+
/**
300+
* Fetch the meta model variant base for this item.
301+
*
302+
* Note: For a non-variant item the variant base is the item itself.
303+
*
304+
* @return IItem The variant base.
305+
*/
306+
public function getVariantBase()
307+
{
308+
if (!$this->isVariantBase()) {
309+
return $this->getMetaModel()->findById($this->get('vargroup'));
310+
}
311+
312+
return $this;
313+
}
314+
299315
/**
300316
* Find all Variants including the variant base.
301317
*

0 commit comments

Comments
 (0)