2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
|
|
|
namespace Wikia\PortableInfobox\Parser\Nodes;
|
2015-05-07 12:37:13 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
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'
|
|
|
|
];
|
2015-04-27 14:05:31 +00:00
|
|
|
|
|
|
|
public function getData() {
|
2015-06-10 09:28:33 +00:00
|
|
|
if ( !isset( $this->data ) ) {
|
2015-06-15 12:57:57 +00:00
|
|
|
$this->data = [ 'value' => $this->getDataForChildren(),
|
2015-06-15 12:58:48 +00:00
|
|
|
'layout' => $this->getLayout() ];
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|
2015-06-10 09:28:33 +00:00
|
|
|
|
|
|
|
return $this->data;
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-06-10 09:28:33 +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() ) {
|
2015-04-27 14:05:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 09:28:33 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-10 15:19:40 +00:00
|
|
|
|
|
|
|
public function getSource() {
|
2015-06-11 09:48:32 +00:00
|
|
|
return $this->getSourceForChildren();
|
2015-06-10 15:19:40 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|