I've set the "Preview Post" in Post Settings to be checked - so that every Create Content form should only shows a "preview" button, and no "Save" button at first.

But, in my Drupal 6.2 install (was 4.7, then 5.7, and now 6.2), after toggling the Preview Post setting just to be sure, I can create all types of content - Blog, Story, Page, Image, etc - without forcing a required preview. I see two buttons "Save" and "Preview", irrespective of the setting of "Preview Post".
This worked fine in 5.7 and 4.7. There are no error messages in the logs when I create content, so the system seems to be installed correctly.

I could not any documentation on whether this behavior has changed, or if there are additional settings that need to made, if anyone has any info, let me know.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bwooster47’s picture

Category: support » bug

I did some digging around in the code.

Drupal 5.7 node module has this code:

  if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
    unset($form['submit']);
  }

in the function node_form_add_preview().

In Drupal 6.2 node module, I can't see code that does a variable_get('node_preview', 0), which seems to indicate that the admin setting for Preview Post would never be taken into account?

The functions have changed between 5.x and 6.x, so I am not sure the right fix for this - but the following code I added to node_form() seems to do the trick - someone more knowledgeable should probably look into this, I added the if statement below to inhibit the Save button:

 // Add the buttons.
  $form['buttons'] = array();
  if (!variable_get('node_preview', 0) || (!form_get_errors() && isset($form_state['node_preview']))) {
     $form['buttons']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#weight' => 5,
      '#submit' => array('node_form_submit'),
    );
  }
dropcube’s picture

Title: Preview required not working in 6.2? » Preview post setting (optional, required) not working
Version: 6.2 » 7.x-dev
Assigned: Unassigned » dropcube
Priority: Normal » Critical
Status: Active » Needs review
FileSize
677 bytes
  // Add the buttons.
  $form['buttons'] = array();
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#access' => !variable_get('node_preview', 0) || !form_get_errors() && isset($form_state['node_preview']),
    '#value' => t('Save'),
    '#weight' => 5,
    '#submit' => array('node_form_submit'),
  );

This is an expected behavior that is not working well in HEAD and 6.x, I am setting this to critical so that it get some attention and can be ported to 6.x before the next maintenance release. The patch applies to HEAD.

dawehner’s picture

i created a module to provide node_preview settings by content typ
i think its sth. which could be in core, or?

Zothos’s picture

i would love to see per content typ preview in :)

Hinode’s picture

I agree that is an issue for a node (e.g. post new forum topic), cause here the config in admin/content/node-settings (Drupal 6.2) do not work.

But, just to remember, forum comments is not affected by the settings in that place, rather, that setting was moved to another place: admin/content/node-type/forum (roll down to comment settings).

BTW, the patch above work for me.

Thanks!

catch’s picture

@dropcube - where is this variable set? It's not in admin/build/types and I'm not sure where else it would be if not there.

dropcube’s picture

Version: 7.x-dev » 6.x-dev

@catch: It's at admin/content/node-settings.

I suggest to fix this bug in 6.x and work out a more complete solution for 7.x, i.e. per content type preview settings. Having per content type settings is worth considering, since some content types may require a preview but other not.

There is a 5.x module for that http://drupal.org/project/nodepreview_by_type...
Would be good to include these settings in 7.x core ?

catch’s picture

@dropcube, sorry, clearly I never look at that page.

Per content type setting makes sense for D7. I can confirm that patch fixes the bug in D6 although I'm not sure why you have to preview again after fixing form errors? Was that in D5? Either way it seems a bit unnecessary - if I fix errors, I want to submit the form usually.

dropcube’s picture

@catch: Yes, it's in D5 this way, in the node_form_add_preview() function:

  if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
    unset($form['submit']);
  }

For me it makes sense in this way... if you are forcing users to preview before submitting, they should be previewing until all the data is correct (validated)... once validated, Ok, submit it now... Makes sense ?

dropcube’s picture

Priority: Critical » Normal

I have created an issue to add this feature to 7.x #281437: Per content type node preview setting

catch’s picture

Status: Needs review » Reviewed & tested by the community

dropcube: fair enough, not really in scope for this issue anyway. Looks good to go.

dropcube’s picture

The patch still applies cleanly.

Gábor Hojtsy’s picture

Version: 6.x-dev » 7.x-dev
FileSize
720 bytes

I've slightly modified the patch to include parenthesis to better show the two conditions. Attached the version I committed to 6.x. I'd suggest you get this into 7.x now and worry about per content type settings later for consistency.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

I've committed Gabor's patch to CVS HEAD. I still think we need to worry about per content type settings as well as write a test or two.

catch’s picture

Per content type settings are here: #281437: Per content type node preview setting Not sure where the tests are best put, so leaving open for now.

Tor Arne Thune’s picture

Title: Preview post setting (optional, required) not working » [Tests needed] Preview post setting (optional, required) not working
Version: 7.x-dev » 8.x-dev
jibran’s picture

I think it is fixed.
This is from Drupal\node\NodeFormController::actions()

    $element = parent::actions($form, $form_state);
    $node = $this->entity;
    $preview_mode = $this->settings['preview'];

    $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview']));
mgifford’s picture

Assigned: dropcube » Unassigned
Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 9ca3de3 on 8.3.x
    - Patch #254242 by Gabor, dropcube: preview post setting (optional,...

  • Dries committed 9ca3de3 on 8.3.x
    - Patch #254242 by Gabor, dropcube: preview post setting (optional,...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 9ca3de3 on 8.4.x
    - Patch #254242 by Gabor, dropcube: preview post setting (optional,...

  • Dries committed 9ca3de3 on 8.4.x
    - Patch #254242 by Gabor, dropcube: preview post setting (optional,...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

  • Dries committed 9ca3de3 on 9.1.x
    - Patch #254242 by Gabor, dropcube: preview post setting (optional,...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Title: [Tests needed] Preview post setting (optional, required) not working » Preview post setting (optional, required) not working
Version: 8.9.x-dev » 7.x-dev
Status: Needs work » Fixed

Moving back to fixed against 7.x - the original bugfix was committed 13 years ago, one follow-up is in an already-fixed issue. We've added lots of test coverage since then, and lack of test coverage isn't a bug.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.