Exemplo n.º 1
0
 /**
  * Returns first node name if nodes is not empty
  *
  * @param GroupNodeDefinition $node
  *
  * @return null|string
  */
 public static function getFirstNodeName(GroupNodeDefinition $node)
 {
     if (!$node->isEmpty()) {
         $firstNode = $node->first();
         return $firstNode->getName();
     }
     return null;
 }
 /**
  * @dataProvider nodeDefinitionProvider
  *
  * @param GroupNodeDefinition $node
  */
 public function testToViewData(GroupNodeDefinition $node)
 {
     $result = $node->toViewData();
     $this->assertArrayHasKey('title', $result);
     $this->assertArrayHasKey('priority', $result);
     $this->assertArrayHasKey('description', $result);
     $this->assertArrayHasKey('icon', $result);
     $this->assertArrayNotHasKey('some_another', $result);
 }
Exemplo n.º 3
0
 /**
  * Test group tree
  *
  * @return GroupNodeDefinition
  */
 protected static function getTestGroup()
 {
     $node1 = new GroupNodeDefinition('node1', array(), array());
     $node1->setLevel(1);
     $node2 = new GroupNodeDefinition('node2', array(), array());
     $node2->setLevel(2);
     $node3 = new GroupNodeDefinition('node3', array(), array($node2));
     $node3->setLevel(1);
     $root = new GroupNodeDefinition('node4', array(), array($node1, $node3));
     $root->setLevel(0);
     return $root;
 }
Exemplo n.º 4
0
 /**
  * Builds group node, called recursively
  *
  * @param array $nodes
  * @param int   $correctFieldsLevel fields should be placed on the same levels that comes from view
  * @param int   $level              current level
  *
  * @throws \Exception
  * @return array
  */
 protected function buildGroupNode($nodes, $correctFieldsLevel, $level = 0)
 {
     $level++;
     foreach ($nodes as $name => $node) {
         if (is_array($node) && isset($node['children'])) {
             if (!isset($this->config[ProcessorDecorator::GROUPS_NODE][$name])) {
                 throw new \Exception(sprintf('Group "%s" does not defined', $name));
             }
             $group = $this->config[ProcessorDecorator::GROUPS_NODE][$name];
             $data = $this->buildGroupNode($node['children'], $correctFieldsLevel, $level);
             $node = new GroupNodeDefinition($name, array_merge($group, $nodes[$name]), $data);
             $node->setLevel($level);
             $nodes[$node->getName()] = $node;
         } else {
             if ($level !== $correctFieldsLevel) {
                 throw new \Exception(sprintf('Field "%s" will not be ever rendered. Please check nesting level', $node));
             }
             $nodes[$name] = $this->buildFieldNode($node);
         }
     }
     return $nodes;
 }
Exemplo n.º 5
0
 /**
  * Builds group node, called recursively
  *
  * @param array $nodes
  * @param int   $correctFieldsLevel fields should be placed on the same levels that comes from view
  * @param int   $level              current level
  *
  * @throws ItemNotFoundException
  * @throws \Exception
  * @return array
  */
 protected function buildGroupNode($nodes, $correctFieldsLevel, $level = 0)
 {
     $level++;
     foreach ($nodes as $name => $node) {
         if (is_array($node) && isset($node['children'])) {
             $group = $this->configBag->getGroupsNode($name);
             if ($group === false) {
                 throw new ItemNotFoundException(sprintf('Group "%s" is not defined.', $name));
             }
             $data = $this->buildGroupNode($node['children'], $correctFieldsLevel, $level);
             $node = new GroupNodeDefinition($name, array_merge($group, $nodes[$name]), $data);
             $node->setLevel($level);
             $nodes[$node->getName()] = $node;
         } else {
             if ($level !== $correctFieldsLevel) {
                 throw new \Exception(sprintf('Field "%s" will not be ever rendered. Please check nesting level', $node));
             }
             $nodes[$name] = $this->buildFieldNode($node);
         }
     }
     return $nodes;
 }