src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php
private function mapContentToNode($document, NodeInterface $node, $locale, $ignoreRequired)
    {
        $structure = $document->getStructure();
        $webspaceName = $this->inspector->getWebspace($document);
        $metadata = $this->inspector->getStructureMetadata($document);

        if (!$metadata) {
            throw new \RuntimeException(
                sprintf(
                    'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?',
                    $document->getStructureType(),
                    $document->getStructureType()
                )
            );
        }

        foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
            if (TitleSubscriber::PROPERTY_NAME === $propertyName) {
                continue;
            }

            $realProperty = $structure->getProperty($propertyName);
            $value = $realProperty->getValue();

            if (false === $ignoreRequired && $structureProperty->isRequired() && null === $value) {
                throw new MandatoryPropertyException(
                    sprintf(
                        'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"',
                        $propertyName,
                        $metadata->getName(),
                        $metadata->getResource()
                    )
                );
            }

            $contentTypeName = $structureProperty->getType();
            $contentType = $this->contentTypeManager->get($contentTypeName);

            // TODO: Only write if the property has been modified.

            $legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
            $legacyProperty->setValue($value);

            $contentType->write(
                new SuluNode($node),
                $legacyProperty,
                null,
                $webspaceName,
                $locale,
                null
            );
        }
    }
private function mapContentToNode($document, NodeInterface $node, $locale, $ignoreRequired)
    {
        $structure = $document->getStructure();
        $webspaceName = $this->inspector->getWebspace($document);
        $metadata = $this->inspector->getStructureMetadata($document);

        if (!$metadata) {
            throw new \RuntimeException(
                sprintf(
                    'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?',
                    $document->getStructureType(),
                    $document->getStructureType()
                )
            );
        }

        foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
            if (TitleSubscriber::PROPERTY_NAME === $propertyName) {
                continue;
            }

            $realProperty = $structure->getProperty($propertyName);
            $value = $realProperty->getValue();

            if (false === $ignoreRequired && $structureProperty->isRequired() && null === $value) {
                throw new MandatoryPropertyException(
                    sprintf(
                        'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"',
                        $propertyName,
                        $metadata->getName(),
                        $metadata->getResource()
                    )
                );
            }

            $contentTypeName = $structureProperty->getType();
            $contentType = $this->contentTypeManager->get($contentTypeName);

            // TODO: Only write if the property has been modified.

            $legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
            $legacyProperty->setValue($value);

            $contentType->write(
                new SuluNode($node),
                $legacyProperty,
                null,
                $webspaceName,
                $locale,
                null
            );
        }
    }
private function mapContentToNode ( $ document , NodeInterface $ node , $ locale , $ ignoreRequired ) { $ structure = $ document -> getStructure ( ) ; $ webspaceName = $ this -> inspector -> getWebspace ( $ document ) ; $ metadata = $ this -> inspector -> getStructureMetadata ( $ document ) ; if ( ! $ metadata ) { throw new \ RuntimeException ( sprintf ( 'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?' , $ document -> getStructureType ( ) , $ document -> getStructureType ( ) ) ) ; } foreach ( $ metadata -> getProperties ( ) as $ propertyName => $ structureProperty ) { if ( TitleSubscriber :: PROPERTY_NAME === $ propertyName ) { continue ; } $ realProperty = $ structure -> getProperty ( $ propertyName ) ; $ value = $ realProperty -> getValue ( ) ; if ( false === $ ignoreRequired && $ structureProperty -> isRequired ( ) && null === $ value ) { throw new MandatoryPropertyException ( sprintf ( 'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"' , $ propertyName , $ metadata -> getName ( ) , $ metadata -> getResource ( ) ) ) ; } $ contentTypeName = $ structureProperty -> getType ( ) ; $ contentType = $ this -> contentTypeManager -> get ( $ contentTypeName ) ; // TODO: Only write if the property has been modified. $ legacyProperty = $ this -> legacyPropertyFactory -> createTranslatedProperty ( $ structureProperty , $ locale ) ; $ legacyProperty -> setValue ( $ value ) ; $ contentType -> write ( new SuluNode ( $ node ) , $ legacyProperty , null , $ webspaceName , $ locale , null ) ; } }
Map to the content properties to the node using the content types.

@param mixed $document
@param NodeInterface $node
@param string $locale
@param bool $ignoreRequired

@throws MandatoryPropertyException
@throws \RuntimeException
Map to the content properties to the node using the content types .