function field_collection_scanner_fields_alter in Search and Replace Scanner 7
Implements hook_scanner_fields_alter().
File
- ./
scanner.module, line 1147 - Search and Replace Scanner - works on all nodes text content.
Code
function field_collection_scanner_fields_alter(array &$all_field_records, $node_bundle = NULL, $parent_bundle = NULL, $parents = NULL) {
// On behalf of field_collection.module.
$query = db_select('field_config_instance', 'instance_parent');
$query
->join('field_config', 'config_parent', 'instance_parent.field_name = config_parent.field_name');
$query
->join('field_config_instance', 'instance_child', 'instance_child.bundle = config_parent.field_name');
$query
->join('field_config', 'config_child', 'instance_child.field_name = config_child.field_name');
$query
->fields('config_child', array(
'field_name',
'module',
));
$query
->fields('instance_parent', array(
'bundle',
));
$query
->addField('config_parent', 'field_name', 'field_collection_name');
if ($parent_bundle) {
$query
->condition('config_parent.field_name', $parent_bundle);
$query
->condition('instance_parent.entity_type', 'field_collection_item');
}
else {
$query
->condition('instance_parent.entity_type', 'node');
}
$query
->condition('instance_child.entity_type', 'field_collection_item');
$query
->condition('config_child.module', array(
'text',
'field_collection',
), 'IN');
$result = $query
->execute();
foreach ($result as $record) {
$field_parents = isset($parents) ? $parents : array(
$record->field_collection_name,
);
$record->node_bundle = isset($node_bundle) ? $node_bundle : $record->bundle;
if ($record->module == 'text') {
$record->field_collection_parents = $field_parents;
$all_field_records[] = $record;
}
elseif ($record->module == 'field_collection') {
// This if statement prevents infinite recursion if a field collection is
// nested within itself.
if (!in_array($record->field_name, $field_parents)) {
$field_parents[] = $record->field_name;
field_collection_scanner_fields_alter($all_field_records, $record->node_bundle, $record->field_name, $field_parents);
}
}
}
}