You are here

function node_teaser_include_verify in Drupal 6

Ensure value of "teaser_include" checkbox is consistent with other form data.

This handles two situations in which an unchecked checkbox is rejected:

1. The user defines a teaser (summary) but it is empty; 2. The user does not define a teaser (summary) (in this case an unchecked checkbox would cause the body to be empty, or missing the auto-generated teaser).

If JavaScript is active then it is used to force the checkbox to be checked when hidden, and so the second case will not arise.

In either case a warning message is output.

1 string reference to 'node_teaser_include_verify'
node_body_field in modules/node/node.pages.inc
Return a node body field, with format and teaser.

File

modules/node/node.module, line 257
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_teaser_include_verify(&$form, &$form_state) {
  $message = '';

  // $form['#post'] is set only when the form is built for preview/submit.
  if (isset($form['#post']['body']) && isset($form_state['values']['teaser_include']) && !$form_state['values']['teaser_include']) {

    // "teaser_include" checkbox is present and unchecked.
    if (strpos($form_state['values']['body'], '<!--break-->') === 0) {

      // Teaser is empty string.
      $message = t('You specified that the summary should not be shown when this post is displayed in full view. This setting is ignored when the summary is empty.');
    }
    elseif (strpos($form_state['values']['body'], '<!--break-->') === FALSE) {

      // Teaser delimiter is not present in the body.
      $message = t('You specified that the summary should not be shown when this post is displayed in full view. This setting has been ignored since you have not defined a summary for the post. (To define a summary, insert the delimiter "&lt;!--break--&gt;" (without the quotes) in the Body of the post to indicate the end of the summary and the start of the main content.)');
    }
    if (!empty($message)) {
      drupal_set_message($message, 'warning');

      // Pass new checkbox value on to preview/submit form processing.
      form_set_value($form['teaser_include'], 1, $form_state);

      // Pass new checkbox value back onto form for those cases
      // in which form is redisplayed.
      $form['teaser_include']['#value'] = 1;
    }
  }
  return $form;
}