You are here

function webform_check_record in Webform 7.3

Same name and namespace in other branches
  1. 6.3 webform.module \webform_check_record()
  2. 7.4 webform.module \webform_check_record()

Utility function to check if a webform record is necessary in the database.

If the node is no longer using any webform settings, this function will delete the settings from the webform table. Note that this function will NOT delete rows from the webform table if the node-type is exclusively used for webforms (per the "webform_node_types_primary" variable).

Parameters

$node: The node object to check if a database entry is still required.

Return value

Returns TRUE if the webform still has a record in the database. Returns FALSE if the webform does not have a record or if the previously existing record was just deleted.

3 calls to webform_check_record()
webform_component_delete_form_submit in includes/webform.components.inc
Submit handler for webform_component_delete_form().
webform_email_delete_form_submit in includes/webform.emails.inc
Submit handler for webform_email_delete_form().
webform_node_update in ./webform.module
Implements hook_node_update().

File

./webform.module, line 3188
This module provides a simple way to create forms and questionnaires.

Code

function webform_check_record(&$node) {
  $webform = $node->webform;
  $webform['record_exists'] = FALSE;
  unset($webform['nid']);

  // Don't include empty values in the comparison, this makes it so modules that
  // extend Webform with empty defaults won't affect cleanup of rows.
  $webform = array_filter($webform);
  $defaults = array_filter(webform_node_defaults());
  if ($webform == $defaults && !in_array($node->type, webform_variable_get('webform_node_types_primary'))) {
    webform_node_delete($node);
    $node->webform = webform_node_defaults();
  }
  return $node->webform['record_exists'];
}