Sulu\Bundle\ContentBundle\Behat\BaseStructureContext::createStructures PHP Метод

createStructures() защищенный Метод

Data should be of the form: array( array( 'title' => null, 'url' => null, 'template' => null, 'locale' => 'de', 'data' => '}', 'parent' => null, ), ),
protected createStructures ( string $type, array $data )
$type string
$data array
    protected function createStructures($type, $data)
    {
        foreach ($data as $structureData) {
            $structureData = array_merge(['title' => null, 'url' => null, 'template' => null, 'locale' => 'de', 'data' => '{}', 'parent' => null, 'published' => true], $structureData);
            $parentUuid = null;
            if ($structureData['parent']) {
                $parentPath = $type === 'page' ? '/cmf/sulu_io/contents' : '/cmf/snippets';
                $parentNode = $this->getPhpcrSession()->getNode($parentPath . $structureData['parent']);
                $parentUuid = $parentNode->getIdentifier();
            }
            $propertyData = [];
            if ($structureData['data']) {
                $propertyData = json_decode($structureData['data'], true);
                if (null === $propertyData) {
                    throw new \Exception('Could not decode json string: "%s"', $structureData['data']);
                }
            }
            $document = $this->getDocumentManager()->create($type);
            $document->setStructureType($structureData['template']);
            $document->setTitle($structureData['title']);
            $document->getStructure()->bind($propertyData);
            $document->setWorkflowStage(WorkflowStage::PUBLISHED);
            if ($document instanceof ResourceSegmentBehavior) {
                $document->setResourceSegment($structureData['url']);
            }
            $persistOptions = [];
            if ($type === 'page') {
                if ($parentUuid) {
                    $document->setParent($this->getDocumentManager()->find($parentUuid, 'de'));
                } else {
                    $persistOptions = ['parent_path' => '/cmf/sulu_io/contents'];
                }
            }
            $this->getDocumentManager()->persist($document, 'de', $persistOptions);
            if ($structureData['published']) {
                $this->getDocumentManager()->publish($document, 'de');
            }
            $this->getDocumentManager()->flush();
        }
    }