4

I tried adding this in entity_presave $entity->setPublished(0); but the node still gets saved as published. How can I make it be set to draft?

3

I have tested with hook_entity_presave() and setPublished(0) and setPublished(FALSE) both worked. So the issue is somewhere else.

If you have workbench moderation installed, you may need to set it to one of your moderation states that set it to unpublished.

See admin/structure/workbench-moderation/states

$entity->set('moderation_state', 'draft');

or

$entity->set('moderation_state', 'unpublished');

or perhaps a custom moderation state.

0

$entity->set('moderation_state', "draft"); worked

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.