2

I have used the following code to delete the preview button which is on one of my create content type pages, but its not doing anything, what am I doing wrong?

function example_module_form_alter(&$form, $form_state, $form_id) {
// Check for a particular content type's node form.
if ($form_id == 'example_content_type_node_form') {
drupal_set_message("entering formId");

unset ($form['preview']);
}
}

the drupal_set_message does go off, so I know that I am entering the if statement. I have put this code in a custom module (example_module).

  • Which version of drupal are you using? – Ephraim Apr 25 '12 at 2:58
  • drupal 6, so @Patrick Kenny's suggestion wont work – user1015214 Apr 25 '12 at 3:07
  • try using a module instead – Ephraim Apr 25 '12 at 3:14
1

You don't need to write the code your self, there are already modules out there for exactly that!

1. Jammer Module (Recommended)

Hide or remove items from displaying including the node and comment preview buttons, node delete button, revision log textarea, workflow form on the workflow tab, and feed icon


2. Preview module (Less Recommended)

  • This module hasn't officially been released yet on Drupal 6 or 7, and it hasn't been updated in quite a while, so you may not want to use it on your live site


However if your using drupal 7, it's already a built in feature:

For Jamming the Preview button for content types in Drupal 7, the functionality is built into core. Visit admin/build/node-type/blog (example for blogs), or by navigation path, Administer - Site building - Content types - edit - Submission form settings fieldset



Edit: Since your using drupal 6, my recommendation is just to go with the Jammer Module.

  • If you want to use a module, use the Jammer module. (drupal.org/project/jammer) The Preview module linked above has not had an official release for D6 or D7 and no work has been done on it for more than two years. – Patrick Kenny Apr 25 '12 at 2:38
  • @PatrickKenny - Good point, I updated my answer. – Ephraim Apr 25 '12 at 2:59
  • I just installed Jammer and I set the option to delete the preview button, but it didn't work! – user1015214 Apr 25 '12 at 3:16
  • could you take a screenshot of what exactly you did? – Ephraim Apr 25 '12 at 3:19
  • You need to clear the cache (drupal.org/node/152983) any time you make a change to the Jammer module's settings. – Patrick Kenny Apr 25 '12 at 3:43
2

You don't need to use custom code to delete the preview button. On the Content Type administration page at admin/structure/types/manage/your_content_type, you can selection Disabled for Preview before submitting under Submission form settings. This will remove the preview button for that content type.

  • I'm using drupal 6 and I dont seem to have that url. Is that a drupal 7 url? How do you do this in drupal 6? – user1015214 Apr 25 '12 at 2:57
  • Yes, my solution is for Drupal 7. On D6, I would use the Jammer module. (drupal.org/project/jammer) – Patrick Kenny Apr 25 '12 at 3:14
0

I needed to do it programmatically; here's the code solution in case anybody else needs to do it this way.

Disables comment preview for ALL node types

/**
 * Disables comment preview button for ALL node types.
 */
function my_module_update_7001() {
  $node_types = array_keys(node_type_get_types());
  foreach ($node_types as $node_type) {
    variable_set('comment_preview_' . $node_type, DRUPAL_DISABLED);
  }
}

If you want to remove the subject/title field from all node types (as I did) add this line below the other variable_set...

variable_set('comment_subject_field_' . $node_type, DRUPAL_DISABLED);

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.