enter image description here

I want that checkbox to be unchecked by default, because currently it's always checked.

And I want this result:

enter image description here

The structure of my content is as follows:

enter image description here

enter image description here

  • 1
    The question is unclear, because you don't need a form alter hook to set default values for entity fields. This is configuration if it belongs to a bundle since the entire bundle is configuration (see the answer from @leymannx) or if the entity doesn't have bundles this is set in the base field definition which you can alter in a hook if it is not your own entity. – 4k4 Aug 20 '18 at 14:26

With a form alter this should work:

function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (isset($form['#entity_type']) && $form['#entity_type'] == 'MY_ENTITY_TYPE') {
    $form['status']['widget']['value']['#default_value'] = 0;

Simply edit your content type's default publishing options under example.com/admin/structure/types/manage/MYCONTENTTYPE (Structure > Content types > MYCONTENTTYPE > Edit).

enter image description here

  • It's a good answer thank you, but in my case the content it has been created generating custom modules so my Content types tab is empty. – Francisco Javier Martnez Prez Aug 20 '18 at 11:03
  • @FranciscoJavierMartnezPrez – OK then please update your question to incorporate this key information and I see that I update my answer. – leymannx Aug 20 '18 at 11:05

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.