Create a Node using PHP?

Hey,
I have a question.

I’ve created 3 NodeTypes and 1 documentNode for an upload Page.
On this page the 3 nodes are integrated.
There are the NodeTypes “Document”, “Document Upload” and “Document List”.

The NodeType “Document” contains information about a file.
The NodeType “Document List” is there to read the NodeTypes of the type “Document” on this page.
The NodeType “Document Upload” is used to upload a file using a form.

The form is used to create a “Document”-Node on this documentNode/pageNode.

Is there a way how I can create the Node?
The file upload works well but I’m not able to create the Nodes and I don’t found any help for my problem.

I think I need the identifier of the Page but I don’t know how to create the Node with the form-finisher using PHP.

Document-Tree:

  • Some.Vendor:Document.pageDocuments
    • SomeVendor: Content.FileUpload
    • SomeVendor:Content.FileList
      • Some.Vendor:Content.File

Have a look at these two packages, maybe they will help you:

That is not what I’m looking for but thank you :slight_smile:

I’ve created a PHP-Script which creates a Node in the first ChildNode of the DocumentNode.

‘$toIdentifier’ is the Identifier of the DocumentNode
‘$title’ the title which was entered in the form

     $contextConfiguration = ['workspaceName' => 'live', 'invisibleContentShown' => true];
     $context = $this->contextFactory->create($contextConfiguration);
     $parentNode = $context->getNodeByIdentifier($toIdentifier);
     $contentCollection = $parentNode->getPrimaryChildNode(); // Main-Collection
     $fileList = $contentCollection->getPrimaryChildNode(); // File-List

     $nodeTemplate = new \Neos\ContentRepository\Domain\Model\NodeTemplate();
     $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('Vendor.Documents:Content.File'));
     $nodeTemplate->setProperty('title',$title);

     $fileList->createNodeFromTemplate($nodeTemplate, $title);

But ‘getPrimaryChildNode()’ is depricated

You can get the path of the parent node and then add /main to it. Then you can search the NodeDataRepository for a node by path:

use Neos\ContentRepository\Domain\Repository\NodeDataRepository;

class ABC
{
    /**
     * @Flow\Inject
     * @var NodeDataRepository
     */
    protected $nodeDataRepository;
    
    public function abc()
    {
        ...
        $contentCollection = $this->nodeDataRepository->findOneByPath($parentNode->getPath() . '/main', $parentNode->getWorkspace());
        ...
    }
}

Does the $fileList already exist? I think, this is the node that should be created, isn’t it?

Does the $fileList already exist? I think, this is the node that should be created, isn’t it?

$fileList already exist. Thats the Collection where the Files are saved
I wanted to create Nodes (with PHP) of the File-NodeType (which has to saved in $fileList)

To your code: I will test it and then report again, if it worked

You can use $node->getChildNodes('Vendor.Package:Section.FileList')[0] to get the $fileList. Let me know if this helps :slight_smile: