function webform_entity_uuid_load in Webform UUID 7
Implements hook_entity_uuid_load().
File
- ./
webform_uuid.module, line 10 - Code for the Webform UUID module.
Code
function webform_entity_uuid_load(&$entities, $entity_type) {
if ($entity_type != 'node') {
return;
}
foreach ($entities as $entity) {
if (empty($entity->webform)) {
continue;
}
// Set the webform nid reference to the parent uuid.
$entity->webform['nid'] = $entity->uuid;
// Set all the webform component nids to the uuid.
foreach ($entity->webform['components'] as $i => $component) {
$entity->webform['components'][$i]['nid'] = $entity->uuid;
}
// Set all the webform email nids to the uuid.
foreach ($entity->webform['emails'] as $i => $email) {
$entity->webform['emails'][$i]['nid'] = $entity->uuid;
}
// Pass webform_validation info if the module is enabled.
// Based on a patch in https://drupal.org/node/1038208.
if (!module_exists('webform_validation')) {
return;
}
$entity->webform['validation'] = array();
// Get all validation rules.
$validation_rules = db_query("SELECT * FROM {webform_validation_rule} WHERE nid = :nid", array(
':nid' => $entity->nid,
));
$rules = new stdClass();
$rules->components = array();
foreach ($validation_rules as $rule) {
$rule->nid = $entity->uuid;
// Get all validation components.
$validation_components = db_query("SELECT * FROM {webform_validation_rule_components} WHERE ruleid = :rid", array(
':rid' => $rule->ruleid,
));
foreach ($validation_components as $component) {
$rule->components[] = $component;
}
// Append the validation rule to the validation array.
$entity->webform['validation'][] = $rule;
}
}
}