Skip to content

Commit

Permalink
Merge pull request #356 from eric-chau/fix-page-state-label
Browse files Browse the repository at this point in the history
[NestedNode] updated Page::getStateLabel to return right label for offline state
  • Loading branch information
mickaelandrieu committed May 7, 2015
2 parents 19ccc9b + 390dd51 commit b7304c2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions NestedNode/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ public function setMetaData(MetaDataBag $metadata = null)
*/
public function setState($state)
{
$state = (int) $state;
if ($this->isRoot() && !($state & Page::STATE_ONLINE)) {
throw new \LogicException("Root page state must be online.");
}
Expand Down Expand Up @@ -1435,20 +1436,20 @@ public function getSiteLabel()
*/
public function getStateLabel()
{
$states = array_flip(self::$STATES);
$label = true === isset($states[$this->_state]) ? $states[$this->_state] : null;
if (null === $label) {
$labels = array();
foreach ($states as $value => $label) {
$labels = [];
if (self::STATE_OFFLINE === $this->_state) {
$labels[] = 'Offline';
} elseif (self::STATE_HIDDEN === $this->_state) {
$labels[] = 'Offline, Hidden';
} else {
foreach (self::$STATES as $label => $value) {
if (0 !== ($this->_state & $value)) {
$labels[] = $label;
}
}

$label = implode(', ', $labels);
}

return $label;
return implode(', ', $labels);
}

/**
Expand Down

0 comments on commit b7304c2

Please sign in to comment.