Commit ca2f0a8c authored by Dries's avatar Dries

Issue #1864720 by yched: Minor hysteresis in field_info_instances().

parent eea79f9b
......@@ -364,9 +364,15 @@ public function getBundleInstances($entity_type, $bundle) {
}
unset($info['fields']);
// Save in the "static" cache.
$this->bundleInstances[$entity_type][$bundle] = $info['instances'];
// Store the instance definitions in the "static" cache'. Empty (or
// non-existent) bundles are stored separately, so that they do not
// pollute the global list returned by getInstances().
if ($info['instances']) {
$this->bundleInstances[$entity_type][$bundle] = $info['instances'];
}
else {
$this->emptyBundles[$entity_type][$bundle] = TRUE;
}
return $info['instances'];
}
......
......@@ -118,6 +118,16 @@ function testFieldInfo() {
$this->assertIdentical($instances, $expected, format_string("field_info_instances('user') returns %expected.", array('%expected' => var_export($expected, TRUE))));
$instances = field_info_instances('user', 'user');
$this->assertIdentical($instances, array(), "field_info_instances('user', 'user') returns an empty array.");
// Test that querying for invalid entity types does not add entries in the
// list returned by field_info_instances().
field_info_cache_clear();
field_info_instances('invalid_entity', 'invalid_bundle');
// Simulate new request by clearing static caches.
drupal_static_reset();
field_info_instances('invalid_entity', 'invalid_bundle');
$instances = field_info_instances();
$this->assertFalse(isset($instances['invalid_entity']), 'field_info_instances() does not contain entries for the invalid entity type that was queried before');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment