Commit 295feb1d authored by webchick's avatar webchick
Browse files

#370037 by bjaspan: Add means of getting all instances of a field.

parent 00e38fb0
...@@ -505,7 +505,9 @@ function field_info_bundle_entity($bundle) { ...@@ -505,7 +505,9 @@ function field_info_bundle_entity($bundle) {
* Return array of all field data, keyed by field name. * Return array of all field data, keyed by field name.
* *
* @return * @return
* An array of Field objects. * An array of Field objects. Each Field object has an additional
* property, bundles, which is an array of all the bundles to which
* this field belongs.
* *
* This function is an autoloader for _field_info_fields() in modules/field/field.info.inc. * This function is an autoloader for _field_info_fields() in modules/field/field.info.inc.
*/ */
...@@ -518,6 +520,11 @@ function field_info_fields() { ...@@ -518,6 +520,11 @@ function field_info_fields() {
* Return data about an individual field. * Return data about an individual field.
* *
* @param $field_name * @param $field_name
* The name of the field to retrieve.
* @return
* The named field object, or NULL. The Field object has an additional
* property, bundles, which is an array of all the bundles to which
* this field belongs.
* *
* This function is an autoloader for _field_info_field() in modules/field/field.info.inc. * This function is an autoloader for _field_info_field() in modules/field/field.info.inc.
*/ */
......
...@@ -156,10 +156,12 @@ function _field_info_collate_types($reset = FALSE) { ...@@ -156,10 +156,12 @@ function _field_info_collate_types($reset = FALSE) {
* If $reset is TRUE, nothing. * If $reset is TRUE, nothing.
* If $reset is FALSE, an array containing the following elements: * If $reset is FALSE, an array containing the following elements:
* *
* fields: array of all defined Field objects, keyed by field name * - fields: array of all defined Field objects, keyed by field
* * name. Each field has an additional element, bundles, which is
* instances: array of bundled field info, keyed by bundle name * an array of all bundles to which the field is assigned.
* * contains all FieldInstance objects for this bundle, keyed by field name. * - instances: array whose keys are bundle names and whose values
* are an array, keyed by field name, of all Instance objects in
* that bundle.
*/ */
function _field_info_collate_fields($reset = FALSE) { function _field_info_collate_fields($reset = FALSE) {
static $info; static $info;
...@@ -184,6 +186,7 @@ function _field_info_collate_fields($reset = FALSE) { ...@@ -184,6 +186,7 @@ function _field_info_collate_fields($reset = FALSE) {
$instances = field_read_instances(); $instances = field_read_instances();
foreach ($instances as $instance) { foreach ($instances as $instance) {
$info['instances'][$instance['bundle']][$instance['field_name']] = $instance; $info['instances'][$instance['bundle']][$instance['field_name']] = $instance;
$info['fields'][$instance['field_name']]['bundles'][] = $instance['bundle'];
} }
cache_set('field_info_fields', $info, 'cache_field'); cache_set('field_info_fields', $info, 'cache_field');
...@@ -389,7 +392,9 @@ function _field_info_bundle_entity($bundle) { ...@@ -389,7 +392,9 @@ function _field_info_bundle_entity($bundle) {
* Return array of all field data, keyed by field name. * Return array of all field data, keyed by field name.
* *
* @return * @return
* An array of Field objects. * An array of Field objects. Each Field object has an additional
* property, bundles, which is an array of all the bundles to which
* this field belongs.
*/ */
function _field_info_fields() { function _field_info_fields() {
$info = _field_info_collate_fields(); $info = _field_info_collate_fields();
...@@ -400,6 +405,11 @@ function _field_info_fields() { ...@@ -400,6 +405,11 @@ function _field_info_fields() {
* Return data about an individual field. * Return data about an individual field.
* *
* @param $field_name * @param $field_name
* The name of the field to retrieve.
* @return
* The named field object, or NULL. The Field object has an additional
* property, bundles, which is an array of all the bundles to which
* this field belongs.
*/ */
function _field_info_field($field_name) { function _field_info_field($field_name) {
$info = _field_info_collate_fields(); $info = _field_info_collate_fields();
......
Supports Markdown
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