Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jun 12 posts 92 karma points
    Dec 23, 2020 @ 23:26
    Jun
    0

    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: enter image description here

    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

  • Keown 13 posts 83 karma points
    Dec 24, 2020 @ 05:26
    Keown
    0

    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();

  • Jun 12 posts 92 karma points
    Jan 04, 2021 @ 01:51
    Jun
    0

    Hey Keown, thanks for your reply, but it is not what I am looking for.

  • Jun 12 posts 92 karma points
    Mar 03, 2021 @ 22:14
    Jun
    0

    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?

Please Sign in or register to post replies

Write your reply to:

Draft