Skip to content

Commit

Permalink
Merge pull request #1087 - add getVariantBase()
Browse files Browse the repository at this point in the history
This implements feature request #237 by adding the requested method:
`IItem::getVariantBase()`.
  • Loading branch information
discordier committed Apr 19, 2017
2 parents 191db54 + 6ef3a24 commit bd9e359
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/MetaModels/IItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of MetaModels/core.
*
* (c) 2012-2015 The MetaModels team.
* (c) 2012-2017 The MetaModels team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,8 @@
* @subpackage Core
* @author Christian Schiffler <[email protected]>
* @author Stefan Heimes <[email protected]>
* @copyright 2012-2015 The MetaModels team.
* @author Richard Henkenjohann <[email protected]>
* @copyright 2012-2017 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0
* @filesource
*/
Expand Down Expand Up @@ -107,10 +108,19 @@ public function isVariantBase();
*
* @param \MetaModels\Filter\IFilter $objFilter The filter settings to be applied.
*
* @return \MetaModels\IItems A list of all variants for this item.
* @return \MetaModels\IItems|null A list of all variants for this item or null if the item cannot handle variants.
*/
public function getVariants($objFilter);

/**
* Fetch the meta model variant base for this item.
*
* Note: For a non-variant item the variant base is the item itself.
*
* @return IItem The variant base.
*/
public function getVariantBase();

/**
* Save the current data for every attribute to the data sink.
*
Expand Down
18 changes: 17 additions & 1 deletion src/MetaModels/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function isVariantBase()
*
* @param IFilter $objFilter The filter settings to be applied.
*
* @return IItems A list of all variants for this item.
* @return IItems|null A list of all variants for this item.
*/
public function getVariants($objFilter)
{
Expand All @@ -296,6 +296,22 @@ public function getVariants($objFilter)
return null;
}

/**
* Fetch the meta model variant base for this item.
*
* Note: For a non-variant item the variant base is the item itself.
*
* @return IItem The variant base.
*/
public function getVariantBase()
{
if (!$this->isVariantBase()) {
return $this->getMetaModel()->findById($this->get('vargroup'));
}

return $this;
}

/**
* Find all Variants including the variant base.
*
Expand Down

0 comments on commit bd9e359

Please sign in to comment.