src/Sulu/Component/Content/Types/ResourceLocator/Strategy/TreeLeafEditStrategy.php
private function adaptResourceLocators(ResourceSegmentBehavior $document, $userId)
    {
        if (!$document instanceof ChildrenBehavior) {
            return;
        }

        $webspaceKey = $this->documentInspector->getWebspace($document);
        $languageCode = $this->documentInspector->getOriginalLocale($document);

        $node = $this->documentInspector->getNode($document);
        $node->getSession()->save();

        foreach ($document->getChildren() as $childDocument) {
            // skip documents without assigned resource segment
            if (!$childDocument instanceof ResourceSegmentBehavior
                || !($currentResourceLocator = $childDocument->getResourceSegment())
            ) {
                $this->adaptResourceLocators($childDocument, $userId);

                continue;
            }

            // build new resource segment based on parent changes
            $parentUuid = $this->documentInspector->getUuid($document);
            $childPart = $this->getChildPart($currentResourceLocator);
            $newResourceLocator = $this->generate($childPart, $parentUuid, $webspaceKey, $languageCode);

            // save new resource locator
            $childNode = $this->documentInspector->getNode($childDocument);
            $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
            $template = $childNode->getPropertyValue($templatePropertyName);
            $structure = $this->structureManager->getStructure($template);

            $property = $structure->getPropertyByTagName('sulu.rlp');
            $property->setValue($newResourceLocator);
            $contentType = $this->contentTypeManager->get($property->getContentTypeName());
            $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
            $contentType->write($childNode, $translatedProperty, $userId, $webspaceKey, $languageCode, null);

            $childDocument->setResourceSegment($newResourceLocator);

            // do not save routes if unpublished
            if (!$childDocument->getPublished()) {
                $this->adaptResourceLocators($childDocument, $userId);
            } else {
                $this->save($childDocument, $userId);
            }
        }
    }
private function adaptResourceLocators(ResourceSegmentBehavior $document, $userId)
    {
        if (!$document instanceof ChildrenBehavior) {
            return;
        }

        $webspaceKey = $this->documentInspector->getWebspace($document);
        $languageCode = $this->documentInspector->getOriginalLocale($document);

        $node = $this->documentInspector->getNode($document);
        $node->getSession()->save();

        foreach ($document->getChildren() as $childDocument) {
            // skip documents without assigned resource segment
            if (!$childDocument instanceof ResourceSegmentBehavior
                || !($currentResourceLocator = $childDocument->getResourceSegment())
            ) {
                $this->adaptResourceLocators($childDocument, $userId);

                continue;
            }

            // build new resource segment based on parent changes
            $parentUuid = $this->documentInspector->getUuid($document);
            $childPart = $this->getChildPart($currentResourceLocator);
            $newResourceLocator = $this->generate($childPart, $parentUuid, $webspaceKey, $languageCode);

            // save new resource locator
            $childNode = $this->documentInspector->getNode($childDocument);
            $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
            $template = $childNode->getPropertyValue($templatePropertyName);
            $structure = $this->structureManager->getStructure($template);

            $property = $structure->getPropertyByTagName('sulu.rlp');
            $property->setValue($newResourceLocator);
            $contentType = $this->contentTypeManager->get($property->getContentTypeName());
            $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
            $contentType->write($childNode, $translatedProperty, $userId, $webspaceKey, $languageCode, null);

            $childDocument->setResourceSegment($newResourceLocator);

            // do not save routes if unpublished
            if (!$childDocument->getPublished()) {
                $this->adaptResourceLocators($childDocument, $userId);
            } else {
                $this->save($childDocument, $userId);
            }
        }
    }
private function adaptResourceLocators ( ResourceSegmentBehavior $ document , $ userId ) { if ( ! $ document instanceof ChildrenBehavior ) { return ; } $ webspaceKey = $ this -> documentInspector -> getWebspace ( $ document ) ; $ languageCode = $ this -> documentInspector -> getOriginalLocale ( $ document ) ; $ node = $ this -> documentInspector -> getNode ( $ document ) ; $ node -> getSession ( ) -> save ( ) ; foreach ( $ document -> getChildren ( ) as $ childDocument ) { // skip documents without assigned resource segment if ( ! $ childDocument instanceof ResourceSegmentBehavior || ! ( $ currentResourceLocator = $ childDocument -> getResourceSegment ( ) ) ) { $ this -> adaptResourceLocators ( $ childDocument , $ userId ) ; continue ; } // build new resource segment based on parent changes $ parentUuid = $ this -> documentInspector -> getUuid ( $ document ) ; $ childPart = $ this -> getChildPart ( $ currentResourceLocator ) ; $ newResourceLocator = $ this -> generate ( $ childPart , $ parentUuid , $ webspaceKey , $ languageCode ) ; // save new resource locator $ childNode = $ this -> documentInspector -> getNode ( $ childDocument ) ; $ templatePropertyName = $ this -> nodeHelper -> getTranslatedPropertyName ( 'template' , $ languageCode ) ; $ template = $ childNode -> getPropertyValue ( $ templatePropertyName ) ; $ structure = $ this -> structureManager -> getStructure ( $ template ) ; $ property = $ structure -> getPropertyByTagName ( 'sulu.rlp' ) ; $ property -> setValue ( $ newResourceLocator ) ; $ contentType = $ this -> contentTypeManager -> get ( $ property -> getContentTypeName ( ) ) ; $ translatedProperty = $ this -> nodeHelper -> getTranslatedProperty ( $ property , $ languageCode ) ; $ contentType -> write ( $ childNode , $ translatedProperty , $ userId , $ webspaceKey , $ languageCode , null ) ; $ childDocument -> setResourceSegment ( $ newResourceLocator ) ; // do not save routes if unpublished if ( ! $ childDocument -> getPublished ( ) ) { $ this -> adaptResourceLocators ( $ childDocument , $ userId ) ; } else { $ this -> save ( $ childDocument , $ userId ) ; } } }
adopts resource locator of children by iteration.

@param ResourceSegmentBehavior $document
@param int $userId
adopts resource locator of children by iteration .