0

I'm creating a node programatically in D8 and passing the value for update field explicitly.
When the node is created it sets the update value which is provided, but when the same node is updated the changed value is set to current time, but when I again update the same node it takes the value which is provided.

Code :

$node_data = [
'title' => 'Test node title',
'changed' => 1594270272
];
 $node = Node::create([
                'type' => 'article'
            ]); //to create new article
$node = Node::load(NID OF ARTICLE CREATED); // to edit already created article
 $node->set('title',$node_data['title']);
 $node->set('changed',(int) $node_data['changed']);
 $node->set('uid',1);
 $node->save();
Case 1 : Created new article with $node_data, updated time is set to 1594270272
Case 2 : Edited the article created in step 1, updated time is set to current timestamp.
Case 3 : Edited the article again created in step 1 and edited in step 2, updated time is set to 1594270272 again.

The same things is happening after every alternate update call.

I want to set the new updated time every time which is passed in $node_data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.