PortableInfobox/services/Parser/Nodes/NodeGroup.php

55 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace Wikia\PortableInfobox\Parser\Nodes;
class NodeGroup extends Node {
2015-06-10 15:24:49 +00:00
const DATA_LAYOUT_ATTR_NAME = 'layout';
2015-06-12 00:11:23 +00:00
const DEFAULT_TAG_NAME = 'default';
2015-06-10 16:07:28 +00:00
private $supportedGroupLayouts = [
'default',
'horizontal'
];
public function getData() {
if ( !isset( $this->data ) ) {
$this->data = [ 'value' => $this->getDataForChildren(),
2015-06-15 12:58:48 +00:00
'layout' => $this->getLayout() ];
}
return $this->data;
}
2015-06-11 09:34:28 +00:00
public function getRenderData() {
return [
'type' => $this->getType(),
2015-06-15 12:58:48 +00:00
'data' => [ 'value' => $this->getRenderDataForChildren(),
'layout' => $this->getLayout() ],
2015-06-11 09:34:28 +00:00
];
}
public function isEmpty() {
2015-06-11 09:34:28 +00:00
/** @var Node $item */
foreach ( $this->getChildNodes() as $item ) {
if ( !$item->isType( 'header' ) && !$item->isEmpty() ) {
return false;
}
}
return true;
}
public function getSource() {
return $this->getSourceForChildren();
}
2015-06-15 12:58:48 +00:00
/**
* @return string
*/
protected function getLayout() {
$layout = $this->getXmlAttribute( $this->xmlNode, self::DATA_LAYOUT_ATTR_NAME );
return ( isset( $layout ) && in_array( $layout, $this->supportedGroupLayouts ) ) ? $layout
: self::DEFAULT_TAG_NAME;
}
}