Skip to content

Commit 0832b67

Browse files
committed
#6: Check entity type and bundle
1 parent a870f81 commit 0832b67

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

conditional_fields.module

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,49 +1299,33 @@ function conditional_fields_load_dependencies($entity_type = NULL, $bundle = NUL
12991299
$select = db_select('conditional_fields', 'cf')
13001300
->fields('cf', array('id', 'options', 'dependee', 'dependent'))
13011301
->orderBy('cf.dependent');
1302-
//$fci_depende = $select->join('field_config_instance', 'fci_dependee', 'cf.dependee = fci_dependee.id');
1303-
//$fci_dependent = $select->join('field_config_instance', 'fci_dependent', 'cf.dependent = fci_dependent.id');
1304-
//$select->addField($fci_depende, 'field_name', 'dependee');
1305-
//$select->addField($fci_dependent, 'field_name', 'dependent');
1306-
//$select->addField($fci_depende, 'entity_type');
1307-
//$select->addField($fci_depende, 'bundle');
1308-
1309-
if (0 && $entity_type) {
1310-
$select->condition(
1311-
db_and()
1312-
->condition('fci_dependee.entity_type', $entity_type)
1313-
->condition('fci_dependent.entity_type', $entity_type)
1314-
);
1315-
}
1316-
1317-
if (0 && $bundle) {
1318-
$select->condition(
1319-
db_and()
1320-
->condition('fci_dependee.bundle', $bundle)
1321-
->condition('fci_dependent.bundle', $bundle)
1322-
);
1323-
}
1324-
//$instance_settings = config_get("field.instance.$entity_type.$bundle.$field_name");
13251302

13261303
$result = $select->execute();
13271304

13281305
foreach ($result as $dependency) {
13291306
$dependent_parts = explode('.', $dependency->dependent);
1330-
$result_entity_type = $entity_type ? $entity_type : $dependent_parts[0];
1331-
$result_bundle = $bundle ? $bundle : $dependent_parts[1];
1332-
1333-
$options = unserialize($dependency->options);
1334-
$options += $default_options;
1335-
1336-
$dependencies[$result_entity_type][$result_bundle]['dependents'][$dependency->dependent][$dependency->id] = array(
1337-
'dependee' => $dependency->dependee,
1338-
'options' => $options,
1339-
);
1340-
1341-
$dependencies[$result_entity_type][$result_bundle]['dependees'][$dependency->dependee][$dependency->id] = array(
1342-
'dependent' => $dependency->dependent,
1343-
'options' => $options,
1344-
);
1307+
$entity_type_match = (!$entity_type || ($entity_type && $dependent_parts[0] == $entity_type));
1308+
$bundle_match = (!$bundle || ($bundle && $dependent_parts[1] == $bundle));
1309+
if ($entity_type_match && $bundle_match) {
1310+
// Make sure there is no Entity type or Bundle specified, or that the
1311+
// specified Entity type or Bundle match the one that is returned
1312+
// in this instance.
1313+
$result_entity_type = $entity_type ? $entity_type : $dependent_parts[0];
1314+
$result_bundle = $bundle ? $bundle : $dependent_parts[1];
1315+
1316+
$options = unserialize($dependency->options);
1317+
$options += $default_options;
1318+
1319+
$dependencies[$result_entity_type][$result_bundle]['dependents'][$dependency->dependent][$dependency->id] = array(
1320+
'dependee' => $dependency->dependee,
1321+
'options' => $options,
1322+
);
1323+
1324+
$dependencies[$result_entity_type][$result_bundle]['dependees'][$dependency->dependee][$dependency->id] = array(
1325+
'dependent' => $dependency->dependent,
1326+
'options' => $options,
1327+
);
1328+
}
13451329
}
13461330
}
13471331

0 commit comments

Comments
 (0)