Passing arbitrary data into a node prior to preprocessing I am looking for a way of passing arbitrary data though node_view() to a preprocess function.

I am using the following code.

  $node = node_load(1);
  $node-&gt;mycustomdata = 'mydata'; // This is the data I want passed through.
  return node_view($node,  'teaser');


I want mycustomdata to be available to me inside my preprocess function so I can add it as a template variable.

function MYMODULE_preprocess_node(&amp;$variables) {
  $node = $variables['node'];
  $variables['mycustomdata'] = $node-&gt;mycustomdata; //  Here is where I want to access the data.
}


How can I achieve this?
Node's in D8 work differently to D7. in D7 node was a stdClass object - basically used in the same way an array was assign a value to a key ($node->value). In D8 Node's are proper objects and can't do the same key/value. Instead, how about creating a field on the node and assigning the value to the field, save the node and then view it?