Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi all,
I want to create a user, then create a node and assign this node to the new user, so the user can edit this node only.
I found the "Content start nodes" can help with the wanted permission setup easily. A wanted end result as below:
I searched and looked into the UserService and ContentService, but could not find anything that can help to update this.
Is it possible to add the new node for the user in code without going through the back office UI?
Thanks in advance, Jun
The following code will help you to save an image in a new node.
use \Drupal\node\Entity\Node; use \Drupal\file\Entity\File;
// Create file object from remote URL. $data = filegetcontents('https://www.drupal.org/files/druplicon.small.png'); $file = filesavedata($data, 'public://druplicon.png', FILEEXISTS_REPLACE);
// Create node object with attached file. $node = Node::create([ 'type' => 'aessuccess', 'title' => 'Druplicon test', 'fieldimage' => [ 'targetid' => $file->id(), 'alt' => 'Hello world', 'title' => 'Goodbye world' ], ]); $node->save();
Hey Keown, thanks for your reply, but it is not what I am looking for.
Thanks for @Marc Goodson, his answer to my other question also resolves what I asked here.
Check out the solution at How do I add a record to umbracoUserStartNode table?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
U8 - How to add start node for user programmatically
Hi all,
I want to create a user, then create a node and assign this node to the new user, so the user can edit this node only.
I found the "Content start nodes" can help with the wanted permission setup easily. A wanted end result as below:
I searched and looked into the UserService and ContentService, but could not find anything that can help to update this.
Is it possible to add the new node for the user in code without going through the back office UI?
Thanks in advance, Jun
The following code will help you to save an image in a new node.
use \Drupal\node\Entity\Node; use \Drupal\file\Entity\File;
// Create file object from remote URL. $data = filegetcontents('https://www.drupal.org/files/druplicon.small.png'); $file = filesavedata($data, 'public://druplicon.png', FILEEXISTS_REPLACE);
// Create node object with attached file. $node = Node::create([ 'type' => 'aessuccess', 'title' => 'Druplicon test', 'fieldimage' => [ 'targetid' => $file->id(), 'alt' => 'Hello world', 'title' => 'Goodbye world' ], ]); $node->save();
Hey Keown, thanks for your reply, but it is not what I am looking for.
Thanks for @Marc Goodson, his answer to my other question also resolves what I asked here.
Check out the solution at How do I add a record to umbracoUserStartNode table?
is working on a reply...