4

I have a content-type that has been created via hook_install. I want to set the "Preview" option to disabled. Currently it defaults to "optional". How can I change this in hook_install when I create the content type?

  • Which Drupal version are you using? – marcvangend Nov 12 '11 at 21:19
  • sorry, drupal 7 – gregghz Nov 12 '11 at 21:29
9

For programming disabling use special variable:

variable_set('node_preview_' . $content_type, '0');

For default node options "Published" (status), "Promoted" (promote), "Sticky" (sticky) and "New revision" (revision) use variable "node_options_" . $content_type, which takes array as a value.
Example can be found in standard installation profile:

// Default "Basic page" to not be promoted and have comments disabled.
variable_set('node_options_page', array('status'));
  • is there a similar variable for "promoted to front page"? I tried 'node_promote_' – gregghz Nov 13 '11 at 1:33
  • 1
    I've updated my answer. Good luck! – kalabro Nov 13 '11 at 14:46
5

If you want more control over when the preview button is disabled you can use hook_form_alter() and then unset($form['actions']['preview']);

Should give you the ability to enable and disable on the fly instead of setting globally.

  • Ick just saw the hook_install() component. @kalabro has the best answer. :) – Citricguy Nov 13 '11 at 5:01
2

Go to the Content Type in the Administration bar and click Edit on the content type you want to adjust. Then at the bottom under Submission Settings change "Preview before Submitting" to disabled.

  • Thanks, I knew about that, but I want it disabled by default when the module is installed (hence "programmatically"). – gregghz Nov 12 '11 at 22:52

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.