/**
  * @param TreeNodeInterface $node
  * @param $userGroup
  */
 private function saveUserGroupDataToCollection(TreeNodeInterface $node, $userGroup)
 {
     $this->objectCollection->add('content_items', $node->getName(), $userGroup->id);
     // Add location to the location list
     if (isset($userGroup->contentInfo)) {
         $this->objectCollection->add('locations', $node->getName(), $userGroup->contentInfo->mainLocationId);
     }
 }
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     $struct = $this->contentTypeService->newFieldDefinitionCreateStruct('', '');
     $this->fillValueObject($struct, $data);
     // Get position from node index (starts from 1)
     $struct->position = $node->getIndex() + 1;
     return $struct;
 }
 /**
  * Gets content type identifier of field corresponding with the given node
  *
  * @param TreeNodeInterface $node
  * @return string
  */
 public function getContentTypeIdentifier(TreeNodeInterface $node)
 {
     $parent = $node->getParent();
     $fieldName = $parent->getName();
     $grandPa = $parent->getParent()->getParent();
     $contentTypeNode = $grandPa->getChildByName('content_type');
     $contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeNode->getValue());
     $fieldDefinition = $contentType->getFieldDefinition($fieldName);
     return $fieldDefinition->fieldTypeIdentifier;
 }
 /**
  * Recursibely loads children of given node
  *
  * @param TreeNodeInterface $node
  * @param array $data
  */
 private function loadChildren($node, &$data)
 {
     foreach ($data as $key => &$item) {
         $child = new Node($key, $node);
         $node->addChild($child);
         $child->setValue($item);
         if (is_array($item)) {
             $this->loadChildren($child, $item);
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     if (!is_array($data)) {
         return null;
     }
     // create structure
     $contentStruct = $this->getContentCreateStruct($data);
     $locationStruct = $this->getLocationCreateStruct($data, self::DEFAULT_LOCATION_ID);
     // publish content object
     $draft = $this->contentService->createContent($contentStruct, array($locationStruct));
     $publishedContent = $this->contentService->publishVersion($draft->versionInfo);
     // Add location to the location list
     if (isset($publishedContent->contentInfo)) {
         $this->objectCollection->add('locations', $node->getName(), $publishedContent->contentInfo->mainLocationId);
     }
     // Add content to content list
     if (isset($publishedContent->contentInfo)) {
         $this->objectCollection->add('content_items', $node->getName(), $publishedContent->id);
     }
     return $publishedContent;
 }
 /**
  * Recursively walks over all tree nodes and call visitors for them
  *
  * @param TreeNodeInterface $node
  * @return mixed
  * @throws NodeDataLoadException
  */
 private function visitNodes(TreeNodeInterface $node)
 {
     try {
         // Collects values from children
         $data = $node->getValue();
         if ($node->hasChildren()) {
             $data = [];
             foreach ($node as $key => $item) {
                 $data[$key] = $this->visitNodes($item);
             }
         }
         // Call visitors for the current node and data collected from children
         $visitors = $this->visitors->getVisitors($node);
         foreach ($visitors as $visitor) {
             $visitResult = $visitor->visit($node, $data);
             if ($visitResult !== null) {
                 $data = $visitResult;
             }
         }
         return $data;
     } catch (\Exception $exception) {
         throw new NodeDataLoadException('Error loading data from ' . $node->getPath(), $exception);
     }
 }
 /**
  * @inheritdoc
  */
 public function addChild(TreeNodeInterface $child)
 {
     $this->items[$child->getName()] = $child;
 }
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     return (string) crc32($node->getValue());
 }