2009-02-03 17:30:13 +00:00
|
|
|
<?php
|
2009-02-08 21:22:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2009-02-10 03:16:15 +00:00
|
|
|
* Field Info API, providing information about available fields and field types.
|
2009-02-08 21:22:59 +00:00
|
|
|
*/
|
2009-02-03 17:30:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup field_info Field Info API
|
|
|
|
* @{
|
|
|
|
* Obtain information about Field API configuration.
|
|
|
|
*
|
|
|
|
* The Field Info API exposes information about field types, fields,
|
|
|
|
* instances, bundles, widget types, display formatters, behaviors,
|
|
|
|
* and settings defined by or with the Field API.
|
2011-11-30 02:42:42 +00:00
|
|
|
*
|
2011-12-22 09:32:53 +00:00
|
|
|
* See @link field Field API @endlink for information about the other parts of
|
|
|
|
* the Field API.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Clears the field info cache without clearing the field data cache.
|
2009-08-11 14:59:40 +00:00
|
|
|
*
|
|
|
|
* This is useful when deleted fields or instances are purged. We
|
|
|
|
* need to remove the purged records, but no actual field data items
|
|
|
|
* are affected.
|
|
|
|
*/
|
2009-09-07 15:49:01 +00:00
|
|
|
function field_info_cache_clear() {
|
2010-10-23 15:55:04 +00:00
|
|
|
drupal_static_reset('field_view_mode_settings');
|
2011-12-30 06:45:45 +00:00
|
|
|
drupal_static_reset('field_available_languages');
|
2010-10-23 15:55:04 +00:00
|
|
|
|
2009-10-31 16:06:36 +00:00
|
|
|
// @todo: Remove this when field_attach_*_bundle() bundle management
|
|
|
|
// functions are moved to the entity API.
|
2009-11-26 05:54:48 +00:00
|
|
|
entity_info_cache_clear();
|
2009-10-31 16:06:36 +00:00
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
_field_info_collate_types_reset();
|
|
|
|
_field_info_collate_fields_reset();
|
2009-08-11 14:59:40 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Collates all information on field types, widget types and related structures.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @return
|
2011-10-20 14:18:46 +00:00
|
|
|
* An associative array containing:
|
2009-12-04 22:46:28 +00:00
|
|
|
* - 'field types': Array of hook_field_info() results, keyed by field_type.
|
|
|
|
* Each element has the following components: label, description, settings,
|
|
|
|
* instance_settings, default_widget, default_formatter, and behaviors
|
|
|
|
* from hook_field_info(), as well as module, giving the module that exposes
|
|
|
|
* the field type.
|
|
|
|
* - 'widget types': Array of hook_field_widget_info() results, keyed by
|
|
|
|
* widget_type. Each element has the following components: label, field
|
|
|
|
* types, settings, and behaviors from hook_field_widget_info(), as well
|
|
|
|
* as module, giving the module that exposes the widget type.
|
|
|
|
* - 'formatter types': Array of hook_field_formatter_info() results, keyed by
|
|
|
|
* formatter_type. Each element has the following components: label, field
|
|
|
|
* types, and behaviors from hook_field_formatter_info(), as well as
|
|
|
|
* module, giving the module that exposes the formatter type.
|
|
|
|
* - 'storage types': Array of hook_field_storage_info() results, keyed by
|
|
|
|
* storage type names. Each element has the following components: label,
|
|
|
|
* description, and settings from hook_field_storage_info(), as well as
|
|
|
|
* module, giving the module that exposes the storage type.
|
|
|
|
* - 'fieldable types': Array of hook_entity_info() results, keyed by
|
|
|
|
* entity_type. Each element has the following components: name, id key,
|
|
|
|
* revision key, bundle key, cacheable, and bundles from hook_entity_info(),
|
|
|
|
* as well as module, giving the module that exposes the entity type.
|
2011-10-20 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @see _field_info_collate_types_reset()
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2011-10-20 14:18:46 +00:00
|
|
|
function _field_info_collate_types() {
|
2012-07-20 04:03:21 +00:00
|
|
|
$language_interface = language_manager(LANGUAGE_TYPE_INTERFACE);
|
2011-10-20 14:18:46 +00:00
|
|
|
|
|
|
|
// Use the advanced drupal_static() pattern, since this is called very often.
|
|
|
|
static $drupal_static_fast;
|
|
|
|
|
|
|
|
if (!isset($drupal_static_fast)) {
|
|
|
|
$drupal_static_fast['field_info_collate_types'] = &drupal_static(__FUNCTION__);
|
|
|
|
}
|
|
|
|
$info = &$drupal_static_fast['field_info_collate_types'];
|
2009-02-03 17:30:13 +00:00
|
|
|
|
2010-02-27 07:41:34 +00:00
|
|
|
// The _info() hooks invoked below include translated strings, so each
|
|
|
|
// language is cached separately.
|
2012-02-22 13:37:04 +00:00
|
|
|
$langcode = $language_interface->langcode;
|
2010-02-27 07:41:34 +00:00
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
if (!isset($info)) {
|
2011-09-11 16:14:18 +00:00
|
|
|
if ($cached = cache('field')->get("field_info_types:$langcode")) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = $cached->data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$info = array(
|
|
|
|
'field types' => array(),
|
|
|
|
'widget types' => array(),
|
|
|
|
'formatter types' => array(),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage types' => array(),
|
2009-02-03 17:30:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Populate field types.
|
|
|
|
foreach (module_implements('field_info') as $module) {
|
|
|
|
$field_types = (array) module_invoke($module, 'field_info');
|
|
|
|
foreach ($field_types as $name => $field_info) {
|
2009-07-30 19:35:47 +00:00
|
|
|
// Provide defaults.
|
|
|
|
$field_info += array(
|
|
|
|
'settings' => array(),
|
|
|
|
'instance_settings' => array(),
|
|
|
|
);
|
2009-02-03 17:30:13 +00:00
|
|
|
$info['field types'][$name] = $field_info;
|
|
|
|
$info['field types'][$name]['module'] = $module;
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 03:12:03 +00:00
|
|
|
drupal_alter('field_info', $info['field types']);
|
2009-02-03 17:30:13 +00:00
|
|
|
|
|
|
|
// Populate widget types.
|
|
|
|
foreach (module_implements('field_widget_info') as $module) {
|
|
|
|
$widget_types = (array) module_invoke($module, 'field_widget_info');
|
|
|
|
foreach ($widget_types as $name => $widget_info) {
|
2009-07-30 19:35:47 +00:00
|
|
|
// Provide defaults.
|
|
|
|
$widget_info += array(
|
|
|
|
'settings' => array(),
|
|
|
|
);
|
2009-02-03 17:30:13 +00:00
|
|
|
$info['widget types'][$name] = $widget_info;
|
|
|
|
$info['widget types'][$name]['module'] = $module;
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 03:12:03 +00:00
|
|
|
drupal_alter('field_widget_info', $info['widget types']);
|
2009-02-03 17:30:13 +00:00
|
|
|
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
// Populate formatter types.
|
2009-02-03 17:30:13 +00:00
|
|
|
foreach (module_implements('field_formatter_info') as $module) {
|
|
|
|
$formatter_types = (array) module_invoke($module, 'field_formatter_info');
|
|
|
|
foreach ($formatter_types as $name => $formatter_info) {
|
2009-07-30 19:35:47 +00:00
|
|
|
// Provide defaults.
|
|
|
|
$formatter_info += array(
|
|
|
|
'settings' => array(),
|
|
|
|
);
|
2009-02-03 17:30:13 +00:00
|
|
|
$info['formatter types'][$name] = $formatter_info;
|
|
|
|
$info['formatter types'][$name]['module'] = $module;
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 03:12:03 +00:00
|
|
|
drupal_alter('field_formatter_info', $info['formatter types']);
|
2009-02-03 17:30:13 +00:00
|
|
|
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
// Populate storage types.
|
|
|
|
foreach (module_implements('field_storage_info') as $module) {
|
|
|
|
$storage_types = (array) module_invoke($module, 'field_storage_info');
|
|
|
|
foreach ($storage_types as $name => $storage_info) {
|
|
|
|
// Provide defaults.
|
|
|
|
$storage_info += array(
|
|
|
|
'settings' => array(),
|
|
|
|
);
|
|
|
|
$info['storage types'][$name] = $storage_info;
|
|
|
|
$info['storage types'][$name]['module'] = $module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drupal_alter('field_storage_info', $info['storage types']);
|
|
|
|
|
2011-09-11 16:14:18 +00:00
|
|
|
cache('field')->set("field_info_types:$langcode", $info);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* Clear collated information on field and widget types and related structures.
|
|
|
|
*/
|
|
|
|
function _field_info_collate_types_reset() {
|
|
|
|
drupal_static_reset('_field_info_collate_types');
|
|
|
|
// Clear all languages.
|
|
|
|
cache('field')->deletePrefix('field_info_types:');
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Collates all information on existing fields and instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @return
|
2011-10-20 14:18:46 +00:00
|
|
|
* An associative array containing:
|
2010-12-17 00:49:56 +00:00
|
|
|
* - fields: Array of existing fields, keyed by field ID. This element
|
|
|
|
* lists deleted and non-deleted fields, but not inactive ones.
|
|
|
|
* Each field has an additional element, 'bundles', which is an array
|
|
|
|
* of all non-deleted instances of that field.
|
|
|
|
* - field_ids: Array of field IDs, keyed by field name. This element
|
|
|
|
* only lists non-deleted, active fields.
|
2010-02-12 05:38:10 +00:00
|
|
|
* - instances: Array of existing instances, keyed by entity type, bundle
|
2010-12-17 00:49:56 +00:00
|
|
|
* name and field name. This element only lists non-deleted instances
|
|
|
|
* whose field is active.
|
2011-10-20 14:18:46 +00:00
|
|
|
*
|
|
|
|
* @see _field_info_collate_fields_reset()
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2011-10-20 14:18:46 +00:00
|
|
|
function _field_info_collate_fields() {
|
|
|
|
// Use the advanced drupal_static() pattern, since this is called very often.
|
|
|
|
static $drupal_static_fast;
|
2009-02-03 17:30:13 +00:00
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
if (!isset($drupal_static_fast)) {
|
|
|
|
$drupal_static_fast['field_info_collate_fields'] = &drupal_static(__FUNCTION__);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
2011-10-20 14:18:46 +00:00
|
|
|
$info = &$drupal_static_fast['field_info_collate_fields'];
|
2009-02-03 17:30:13 +00:00
|
|
|
|
|
|
|
if (!isset($info)) {
|
2011-09-11 16:14:18 +00:00
|
|
|
if ($cached = cache('field')->get('field_info_fields')) {
|
2010-06-29 18:46:12 +00:00
|
|
|
$info = $cached->data;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-08-11 14:59:40 +00:00
|
|
|
$definitions = array(
|
|
|
|
'field_ids' => field_read_fields(array(), array('include_deleted' => 1)),
|
|
|
|
'instances' => field_read_instances(),
|
2009-02-03 17:30:13 +00:00
|
|
|
);
|
|
|
|
|
2010-06-29 18:46:12 +00:00
|
|
|
// Populate 'fields' with all fields, keyed by ID.
|
|
|
|
$info['fields'] = array();
|
|
|
|
foreach ($definitions['field_ids'] as $key => $field) {
|
|
|
|
$info['fields'][$key] = $definitions['field_ids'][$key] = _field_info_prepare_field($field);
|
|
|
|
}
|
2009-08-02 11:24:21 +00:00
|
|
|
|
2010-06-29 18:46:12 +00:00
|
|
|
// Build an array of field IDs for non-deleted fields, keyed by name.
|
|
|
|
$info['field_ids'] = array();
|
|
|
|
foreach ($info['fields'] as $key => $field) {
|
|
|
|
if (!$field['deleted']) {
|
|
|
|
$info['field_ids'][$field['field_name']] = $key;
|
|
|
|
}
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-29 18:46:12 +00:00
|
|
|
// Populate 'instances'. Only non-deleted instances are considered.
|
|
|
|
$info['instances'] = array();
|
|
|
|
foreach (field_info_bundles() as $entity_type => $bundles) {
|
|
|
|
foreach ($bundles as $bundle => $bundle_info) {
|
|
|
|
$info['instances'][$entity_type][$bundle] = array();
|
|
|
|
}
|
2009-10-25 02:51:28 +00:00
|
|
|
}
|
2010-06-29 18:46:12 +00:00
|
|
|
foreach ($definitions['instances'] as $instance) {
|
|
|
|
$field = $info['fields'][$instance['field_id']];
|
|
|
|
$instance = _field_info_prepare_instance($instance, $field);
|
|
|
|
$info['instances'][$instance['entity_type']][$instance['bundle']][$instance['field_name']] = $instance;
|
|
|
|
// Enrich field definitions with the list of bundles where they have
|
|
|
|
// instances. NOTE: Deleted fields in $info['field_ids'] are not
|
|
|
|
// enriched because all of their instances are deleted, too, and
|
|
|
|
// are thus not in $definitions['instances'].
|
|
|
|
$info['fields'][$instance['field_id']]['bundles'][$instance['entity_type']][] = $instance['bundle'];
|
|
|
|
}
|
2010-08-03 01:54:24 +00:00
|
|
|
|
|
|
|
// Populate 'extra_fields'.
|
|
|
|
$extra = module_invoke_all('field_extra_fields');
|
|
|
|
drupal_alter('field_extra_fields', $extra);
|
|
|
|
// Merge in saved settings.
|
|
|
|
foreach ($extra as $entity_type => $bundles) {
|
|
|
|
foreach ($bundles as $bundle => $extra_fields) {
|
|
|
|
$extra_fields = _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle);
|
|
|
|
$info['extra_fields'][$entity_type][$bundle] = $extra_fields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:14:18 +00:00
|
|
|
cache('field')->set('field_info_fields', $info);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* Clear collated information on existing fields and instances.
|
|
|
|
*/
|
|
|
|
function _field_info_collate_fields_reset() {
|
|
|
|
drupal_static_reset('_field_info_collate_fields');
|
|
|
|
cache('field')->delete('field_info_fields');
|
|
|
|
}
|
|
|
|
|
2009-12-04 22:46:28 +00:00
|
|
|
/**
|
|
|
|
* Prepares a field definition for the current run-time context.
|
2009-08-02 11:24:21 +00:00
|
|
|
*
|
|
|
|
* Since the field was last saved or updated, new field settings can be
|
|
|
|
* expected.
|
|
|
|
*
|
|
|
|
* @param $field
|
|
|
|
* The raw field structure as read from the database.
|
|
|
|
*/
|
|
|
|
function _field_info_prepare_field($field) {
|
|
|
|
// Make sure all expected field settings are present.
|
|
|
|
$field['settings'] += field_info_field_settings($field['type']);
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
$field['storage']['settings'] += field_info_storage_settings($field['storage']['type']);
|
2009-08-02 11:24:21 +00:00
|
|
|
|
2010-01-13 04:37:03 +00:00
|
|
|
// Add storage details.
|
|
|
|
$details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field);
|
|
|
|
drupal_alter('field_storage_details', $details, $field, $instance);
|
|
|
|
$field['storage']['details'] = $details;
|
|
|
|
|
2010-02-15 22:18:35 +00:00
|
|
|
// Initialize the 'bundles' list.
|
|
|
|
$field['bundles'] = array();
|
|
|
|
|
2009-08-02 11:24:21 +00:00
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Prepares an instance definition for the current run-time context.
|
2009-08-02 11:24:21 +00:00
|
|
|
*
|
|
|
|
* Since the instance was last saved or updated, a number of things might have
|
2010-10-23 15:55:04 +00:00
|
|
|
* changed: widgets or formatters disabled, new settings expected, new view
|
2009-08-02 11:24:21 +00:00
|
|
|
* modes added...
|
|
|
|
*
|
|
|
|
* @param $instance
|
|
|
|
* The raw instance structure as read from the database.
|
|
|
|
* @param $field
|
|
|
|
* The field structure for the instance.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Field instance array.
|
2009-08-02 11:24:21 +00:00
|
|
|
*/
|
|
|
|
function _field_info_prepare_instance($instance, $field) {
|
|
|
|
// Make sure all expected instance settings are present.
|
|
|
|
$instance['settings'] += field_info_instance_settings($field['type']);
|
|
|
|
|
2009-08-19 13:31:14 +00:00
|
|
|
// Set a default value for the instance.
|
|
|
|
if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && !isset($instance['default_value'])) {
|
|
|
|
$instance['default_value'] = NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-20 21:08:26 +00:00
|
|
|
$instance['widget'] = _field_info_prepare_instance_widget($field, $instance['widget']);
|
2009-08-02 11:24:21 +00:00
|
|
|
|
2009-12-26 16:50:09 +00:00
|
|
|
foreach ($instance['display'] as $view_mode => $display) {
|
|
|
|
$instance['display'][$view_mode] = _field_info_prepare_instance_display($field, $display);
|
2009-08-02 11:24:21 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 15:55:04 +00:00
|
|
|
// Fallback to 'hidden' for view modes configured to use custom display
|
|
|
|
// settings, and for which the instance has no explicit settings.
|
2010-03-27 05:52:50 +00:00
|
|
|
$entity_info = entity_get_info($instance['entity_type']);
|
2010-10-23 15:55:04 +00:00
|
|
|
$view_modes = array_merge(array('default'), array_keys($entity_info['view modes']));
|
|
|
|
$view_mode_settings = field_view_mode_settings($instance['entity_type'], $instance['bundle']);
|
|
|
|
foreach ($view_modes as $view_mode) {
|
|
|
|
if ($view_mode == 'default' || !empty($view_mode_settings[$view_mode]['custom_settings'])) {
|
|
|
|
if (!isset($instance['display'][$view_mode])) {
|
|
|
|
$instance['display'][$view_mode] = array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'label' => 'above',
|
|
|
|
'settings' => array(),
|
|
|
|
'weight' => 0,
|
|
|
|
);
|
|
|
|
}
|
2009-08-02 11:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-20 21:08:26 +00:00
|
|
|
* Adapts display specifications to the current run-time context.
|
|
|
|
*
|
|
|
|
* @param $field
|
|
|
|
* The field structure for the instance.
|
|
|
|
* @param $display
|
|
|
|
* Display specifications as found in
|
2009-12-26 16:50:09 +00:00
|
|
|
* $instance['display']['some_view_mode'].
|
2009-12-20 21:08:26 +00:00
|
|
|
*/
|
|
|
|
function _field_info_prepare_instance_display($field, $display) {
|
|
|
|
$field_type = field_info_field_types($field['type']);
|
|
|
|
|
|
|
|
// Fill in default values.
|
|
|
|
$display += array(
|
|
|
|
'label' => 'above',
|
|
|
|
'type' => $field_type['default_formatter'],
|
|
|
|
'settings' => array(),
|
|
|
|
'weight' => 0,
|
|
|
|
);
|
|
|
|
if ($display['type'] != 'hidden') {
|
|
|
|
$formatter_type = field_info_formatter_types($display['type']);
|
|
|
|
// Fallback to default formatter if formatter type is not available.
|
|
|
|
if (!$formatter_type) {
|
|
|
|
$display['type'] = $field_type['default_formatter'];
|
|
|
|
$formatter_type = field_info_formatter_types($display['type']);
|
|
|
|
}
|
|
|
|
$display['module'] = $formatter_type['module'];
|
|
|
|
// Fill in default settings for the formatter.
|
|
|
|
$display['settings'] += field_info_formatter_settings($display['type']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $display;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares widget specifications for the current run-time context.
|
|
|
|
*
|
|
|
|
* @param $field
|
|
|
|
* The field structure for the instance.
|
|
|
|
* @param $widget
|
|
|
|
* Widget specifications as found in $instance['widget'].
|
|
|
|
*/
|
|
|
|
function _field_info_prepare_instance_widget($field, $widget) {
|
|
|
|
$field_type = field_info_field_types($field['type']);
|
|
|
|
|
|
|
|
// Fill in default values.
|
|
|
|
$widget += array(
|
|
|
|
'type' => $field_type['default_widget'],
|
|
|
|
'settings' => array(),
|
|
|
|
'weight' => 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
$widget_type = field_info_widget_types($widget['type']);
|
|
|
|
// Fallback to default formatter if formatter type is not available.
|
|
|
|
if (!$widget_type) {
|
|
|
|
$widget['type'] = $field_type['default_widget'];
|
|
|
|
$widget_type = field_info_widget_types($widget['type']);
|
|
|
|
}
|
|
|
|
$widget['module'] = $widget_type['module'];
|
|
|
|
// Fill in default settings for the widget.
|
|
|
|
$widget['settings'] += field_info_widget_settings($widget['type']);
|
|
|
|
|
|
|
|
return $widget;
|
|
|
|
}
|
|
|
|
|
2010-08-03 01:54:24 +00:00
|
|
|
/**
|
|
|
|
* Prepares 'extra fields' for the current run-time context.
|
|
|
|
*
|
|
|
|
* @param $extra_fields
|
|
|
|
* The array of extra fields, as collected in hook_field_extra_fields().
|
|
|
|
* @param $entity_type
|
|
|
|
* The entity type.
|
|
|
|
* @param $bundle
|
|
|
|
* The bundle name.
|
|
|
|
*/
|
|
|
|
function _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle) {
|
|
|
|
$entity_type_info = entity_get_info($entity_type);
|
|
|
|
$bundle_settings = field_bundle_settings($entity_type, $bundle);
|
|
|
|
$extra_fields += array('form' => array(), 'display' => array());
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
// Extra fields in forms.
|
|
|
|
foreach ($extra_fields['form'] as $name => $field_data) {
|
|
|
|
$settings = isset($bundle_settings['extra_fields']['form'][$name]) ? $bundle_settings['extra_fields']['form'][$name] : array();
|
|
|
|
if (isset($settings['weight'])) {
|
|
|
|
$field_data['weight'] = $settings['weight'];
|
|
|
|
}
|
|
|
|
$result['form'][$name] = $field_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra fields in displayed entities.
|
|
|
|
$data = $extra_fields['display'];
|
|
|
|
foreach ($extra_fields['display'] as $name => $field_data) {
|
|
|
|
$settings = isset($bundle_settings['extra_fields']['display'][$name]) ? $bundle_settings['extra_fields']['display'][$name] : array();
|
|
|
|
$view_modes = array_merge(array('default'), array_keys($entity_type_info['view modes']));
|
|
|
|
foreach ($view_modes as $view_mode) {
|
|
|
|
if (isset($settings[$view_mode])) {
|
|
|
|
$field_data['display'][$view_mode] = $settings[$view_mode];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$field_data['display'][$view_mode] = array(
|
|
|
|
'weight' => $field_data['weight'],
|
|
|
|
'visible' => TRUE,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($field_data['weight']);
|
|
|
|
$result['display'][$name] = $field_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:38:05 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Determines the behavior of a widget with respect to an operation.
|
|
|
|
*
|
|
|
|
* @param $op
|
|
|
|
* The name of the operation. Currently supported: 'default value',
|
|
|
|
* 'multiple values'.
|
|
|
|
* @param $instance
|
|
|
|
* The field instance array.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* One of these values:
|
|
|
|
* - FIELD_BEHAVIOR_NONE: Do nothing for this operation.
|
|
|
|
* - FIELD_BEHAVIOR_CUSTOM: Use the widget's callback function.
|
|
|
|
* - FIELD_BEHAVIOR_DEFAULT: Use field.module default behavior.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_behaviors_widget($op, $instance) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_widget_types($instance['widget']['type']);
|
|
|
|
return isset($info['behaviors'][$op]) ? $info['behaviors'][$op] : FIELD_BEHAVIOR_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns information about field types from hook_field_info().
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $field_type
|
2011-06-09 03:42:04 +00:00
|
|
|
* (optional) A field type name. If omitted, all field types will be
|
2009-02-03 17:30:13 +00:00
|
|
|
* returned.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
|
|
|
* Either a field type description, as provided by hook_field_info(), or an
|
|
|
|
* array of all existing field types, keyed by field type name.
|
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_field_types($field_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_types();
|
|
|
|
$field_types = $info['field types'];
|
|
|
|
if ($field_type) {
|
|
|
|
if (isset($field_types[$field_type])) {
|
|
|
|
return $field_types[$field_type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $field_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns information about field widgets from hook_field_widget_info().
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $widget_type
|
2011-06-09 03:42:04 +00:00
|
|
|
* (optional) A widget type name. If omitted, all widget types will be
|
2009-02-03 17:30:13 +00:00
|
|
|
* returned.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
2009-12-04 22:46:28 +00:00
|
|
|
* Either a single widget type description, as provided by
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* hook_field_widget_info(), or an array of all existing widget types, keyed
|
|
|
|
* by widget type name.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_widget_types($widget_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_types();
|
|
|
|
$widget_types = $info['widget types'];
|
|
|
|
if ($widget_type) {
|
|
|
|
if (isset($widget_types[$widget_type])) {
|
|
|
|
return $widget_types[$widget_type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $widget_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns information about field formatters from hook_field_formatter_info().
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $formatter_type
|
2011-06-09 03:42:04 +00:00
|
|
|
* (optional) A formatter type name. If omitted, all formatter types will be
|
2009-02-03 17:30:13 +00:00
|
|
|
* returned.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
2009-12-04 22:46:28 +00:00
|
|
|
* Either a single formatter type description, as provided by
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* hook_field_formatter_info(), or an array of all existing formatter types,
|
|
|
|
* keyed by formatter type name.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_formatter_types($formatter_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_types();
|
|
|
|
$formatter_types = $info['formatter types'];
|
|
|
|
if ($formatter_type) {
|
|
|
|
if (isset($formatter_types[$formatter_type])) {
|
|
|
|
return $formatter_types[$formatter_type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $formatter_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns information about field storage from hook_field_storage_info().
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
*
|
|
|
|
* @param $storage_type
|
2011-06-09 03:42:04 +00:00
|
|
|
* (optional) A storage type name. If omitted, all storage types will be
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* returned.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* @return
|
|
|
|
* Either a storage type description, as provided by
|
|
|
|
* hook_field_storage_info(), or an array of all existing storage types,
|
|
|
|
* keyed by storage type name.
|
|
|
|
*/
|
|
|
|
function field_info_storage_types($storage_type = NULL) {
|
|
|
|
$info = _field_info_collate_types();
|
|
|
|
$storage_types = $info['storage types'];
|
|
|
|
if ($storage_type) {
|
|
|
|
if (isset($storage_types[$storage_type])) {
|
|
|
|
return $storage_types[$storage_type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $storage_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns information about existing bundles.
|
2009-10-15 12:44:36 +00:00
|
|
|
*
|
2010-02-11 17:44:47 +00:00
|
|
|
* @param $entity_type
|
2010-02-12 05:38:10 +00:00
|
|
|
* The type of entity; e.g. 'node' or 'user'.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-10-15 12:44:36 +00:00
|
|
|
* @return
|
2010-02-11 17:44:47 +00:00
|
|
|
* An array of bundles for the $entity_type keyed by bundle name,
|
|
|
|
* or, if no $entity_type was provided, the array of all existing bundles,
|
2010-02-12 05:38:10 +00:00
|
|
|
* keyed by entity type.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2010-02-11 17:44:47 +00:00
|
|
|
function field_info_bundles($entity_type = NULL) {
|
2009-10-31 16:06:36 +00:00
|
|
|
$info = entity_get_info();
|
2009-10-15 12:44:36 +00:00
|
|
|
|
2010-02-11 17:44:47 +00:00
|
|
|
if ($entity_type) {
|
|
|
|
return isset($info[$entity_type]['bundles']) ? $info[$entity_type]['bundles'] : array();
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 12:44:36 +00:00
|
|
|
$bundles = array();
|
2009-10-31 16:06:36 +00:00
|
|
|
foreach ($info as $type => $entity_info) {
|
|
|
|
$bundles[$type] = $entity_info['bundles'];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
2009-10-15 12:44:36 +00:00
|
|
|
return $bundles;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns all field definitions.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @return
|
2009-11-29 22:33:47 +00:00
|
|
|
* An array of field definitions, keyed by field name. Each field has an
|
2009-11-29 06:35:47 +00:00
|
|
|
* additional property, 'bundles', which is an array of all the bundles to
|
2010-06-03 21:06:38 +00:00
|
|
|
* which this field belongs keyed by entity type.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-11-29 06:35:47 +00:00
|
|
|
function field_info_fields() {
|
2010-07-26 16:59:24 +00:00
|
|
|
$fields = array();
|
2009-11-29 06:35:47 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2010-06-29 18:46:12 +00:00
|
|
|
foreach ($info['fields'] as $key => $field) {
|
|
|
|
if (!$field['deleted']) {
|
|
|
|
$fields[$field['field_name']] = $field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fields;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns data about an individual field, given a field name.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $field_name
|
2009-08-11 14:59:40 +00:00
|
|
|
* The name of the field to retrieve. $field_name can only refer to a
|
2012-01-31 08:12:57 +00:00
|
|
|
* non-deleted, active field. For deleted fields, use
|
|
|
|
* field_info_field_by_id(). To retrieve information about inactive fields,
|
|
|
|
* use field_read_fields().
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-10 16:09:00 +00:00
|
|
|
* @return
|
2009-12-04 22:46:28 +00:00
|
|
|
* The field array, as returned by field_read_fields(), with an
|
|
|
|
* additional element 'bundles', whose value is an array of all the bundles
|
2012-07-18 13:23:01 +00:00
|
|
|
* this field belongs to keyed by entity type. NULL if the field was not
|
|
|
|
* found.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2010-03-26 17:14:46 +00:00
|
|
|
* @see field_info_field_by_id()
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_field($field_name) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2010-06-29 18:46:12 +00:00
|
|
|
if (isset($info['field_ids'][$field_name])) {
|
|
|
|
return $info['fields'][$info['field_ids'][$field_name]];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns data about an individual field, given a field ID.
|
2009-08-11 14:59:40 +00:00
|
|
|
*
|
|
|
|
* @param $field_id
|
|
|
|
* The id of the field to retrieve. $field_id can refer to a
|
2012-01-31 08:12:57 +00:00
|
|
|
* deleted field, but not an inactive one.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-08-11 14:59:40 +00:00
|
|
|
* @return
|
2009-12-04 22:46:28 +00:00
|
|
|
* The field array, as returned by field_read_fields(), with an
|
|
|
|
* additional element 'bundles', whose value is an array of all the bundles
|
|
|
|
* this field belongs to.
|
|
|
|
*
|
2010-03-26 17:14:46 +00:00
|
|
|
* @see field_info_field()
|
2009-08-11 14:59:40 +00:00
|
|
|
*/
|
|
|
|
function field_info_field_by_id($field_id) {
|
|
|
|
$info = _field_info_collate_fields();
|
2010-06-29 18:46:12 +00:00
|
|
|
if (isset($info['fields'][$field_id])) {
|
|
|
|
return $info['fields'][$field_id];
|
2009-08-11 14:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:49:35 +00:00
|
|
|
/**
|
|
|
|
* Returns the same data as field_info_field_by_id() for every field.
|
|
|
|
*
|
|
|
|
* This function is typically used when handling all fields of some entities
|
|
|
|
* to avoid thousands of calls to field_info_field_by_id().
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* An array, each key is a field ID and the values are field arrays as
|
|
|
|
* returned by field_read_fields(), with an additional element 'bundles',
|
|
|
|
* whose value is an array of all the bundle this field belongs to.
|
|
|
|
*
|
|
|
|
* @see field_info_field()
|
|
|
|
* @see field_info_field_by_id()
|
|
|
|
*/
|
|
|
|
function field_info_field_by_ids() {
|
|
|
|
$info = _field_info_collate_fields();
|
|
|
|
return $info['fields'];
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Retrieves information about field instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
2010-02-11 17:44:47 +00:00
|
|
|
* @param $entity_type
|
2010-02-12 05:38:10 +00:00
|
|
|
* The entity type for which to return instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
* @param $bundle_name
|
2009-10-15 12:44:36 +00:00
|
|
|
* The bundle name for which to return instances.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-10-15 12:44:36 +00:00
|
|
|
* @return
|
2010-02-12 05:38:10 +00:00
|
|
|
* If $entity_type is not set, return all instances keyed by entity type and
|
|
|
|
* bundle name. If $entity_type is set, return all instances for that entity
|
2010-02-11 17:44:47 +00:00
|
|
|
* type, keyed by bundle name. If $entity_type and $bundle_name are set, return
|
2009-10-15 12:44:36 +00:00
|
|
|
* all instances for that bundle.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2010-02-11 17:44:47 +00:00
|
|
|
function field_info_instances($entity_type = NULL, $bundle_name = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2012-02-27 03:45:36 +00:00
|
|
|
|
|
|
|
if (isset($entity_type) && isset($bundle_name)) {
|
|
|
|
return isset($info['instances'][$entity_type][$bundle_name]) ? $info['instances'][$entity_type][$bundle_name] : array();
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
2012-02-27 03:45:36 +00:00
|
|
|
elseif (isset($entity_type)) {
|
|
|
|
return isset($info['instances'][$entity_type]) ? $info['instances'][$entity_type] : array();
|
2009-10-15 12:44:36 +00:00
|
|
|
}
|
2012-02-27 03:45:36 +00:00
|
|
|
else {
|
|
|
|
return $info['instances'];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns an array of instance data for a specific field and bundle.
|
2009-10-15 12:44:36 +00:00
|
|
|
*
|
2010-02-11 17:44:47 +00:00
|
|
|
* @param $entity_type
|
2010-02-12 05:38:10 +00:00
|
|
|
* The entity type for the instance.
|
2009-10-15 12:44:36 +00:00
|
|
|
* @param $field_name
|
|
|
|
* The field name for the instance.
|
|
|
|
* @param $bundle_name
|
|
|
|
* The bundle name for the instance.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2010-02-11 17:44:47 +00:00
|
|
|
function field_info_instance($entity_type, $field_name, $bundle_name) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2010-02-11 17:44:47 +00:00
|
|
|
if (isset($info['instances'][$entity_type][$bundle_name][$field_name])) {
|
|
|
|
return $info['instances'][$entity_type][$bundle_name][$field_name];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 23:01:14 +00:00
|
|
|
/**
|
|
|
|
* Returns a list and settings of pseudo-field elements in a given bundle.
|
|
|
|
*
|
|
|
|
* If $context is 'form', an array with the following structure:
|
|
|
|
* @code
|
|
|
|
* array(
|
|
|
|
* 'name_of_pseudo_field_component' => array(
|
|
|
|
* 'label' => The human readable name of the component,
|
|
|
|
* 'description' => A short description of the component content,
|
|
|
|
* 'weight' => The weight of the component in edit forms,
|
|
|
|
* ),
|
|
|
|
* 'name_of_other_pseudo_field_component' => array(
|
|
|
|
* // ...
|
|
|
|
* ),
|
|
|
|
* );
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* If $context is 'display', an array with the following structure:
|
|
|
|
* @code
|
|
|
|
* array(
|
|
|
|
* 'name_of_pseudo_field_component' => array(
|
|
|
|
* 'label' => The human readable name of the component,
|
|
|
|
* 'description' => A short description of the component content,
|
|
|
|
* // One entry per view mode, including the 'default' mode:
|
|
|
|
* 'display' => array(
|
|
|
|
* 'default' => array(
|
|
|
|
* 'weight' => The weight of the component in displayed entities in
|
|
|
|
* this view mode,
|
2011-05-08 20:18:15 +00:00
|
|
|
* 'visible' => TRUE if the component is visible, FALSE if hidden, in
|
2010-08-03 23:01:14 +00:00
|
|
|
* displayed entities in this view mode,
|
|
|
|
* ),
|
|
|
|
* 'teaser' => array(
|
|
|
|
* // ...
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* 'name_of_other_pseudo_field_component' => array(
|
|
|
|
* // ...
|
|
|
|
* ),
|
|
|
|
* );
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* @param $entity_type
|
|
|
|
* The type of entity; e.g. 'node' or 'user'.
|
|
|
|
* @param $bundle
|
|
|
|
* The bundle name.
|
|
|
|
* @param $context
|
|
|
|
* The context for which the list of pseudo-fields is requested. Either
|
|
|
|
* 'form' or 'display'.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The array of pseudo-field elements in the bundle.
|
|
|
|
*/
|
|
|
|
function field_info_extra_fields($entity_type, $bundle, $context) {
|
|
|
|
$info = _field_info_collate_fields();
|
|
|
|
if (isset($info['extra_fields'][$entity_type][$bundle][$context])) {
|
|
|
|
return $info['extra_fields'][$entity_type][$bundle][$context];
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2010-09-11 00:03:42 +00:00
|
|
|
/**
|
|
|
|
* Returns the maximum weight of all the components in an entity.
|
|
|
|
*
|
|
|
|
* This includes fields, 'extra_fields', and other components added by
|
|
|
|
* third-party modules (e.g. field_group).
|
|
|
|
*
|
|
|
|
* @param $entity_type
|
|
|
|
* The type of entity; e.g. 'node' or 'user'.
|
|
|
|
* @param $bundle
|
|
|
|
* The bundle name.
|
|
|
|
* @param $context
|
|
|
|
* The context for which the maximum weight is requested. Either 'form', or
|
|
|
|
* the name of a view mode.
|
|
|
|
* @return
|
|
|
|
* The maximum weight of the entity's components, or NULL if no components
|
|
|
|
* were found.
|
|
|
|
*/
|
|
|
|
function field_info_max_weight($entity_type, $bundle, $context) {
|
|
|
|
$weights = array();
|
|
|
|
|
|
|
|
// Collect weights for fields.
|
|
|
|
foreach (field_info_instances($entity_type, $bundle) as $instance) {
|
|
|
|
if ($context == 'form') {
|
|
|
|
$weights[] = $instance['widget']['weight'];
|
|
|
|
}
|
2011-01-24 12:51:08 +00:00
|
|
|
elseif (isset($instance['display'][$context]['weight'])) {
|
2010-09-11 00:03:42 +00:00
|
|
|
$weights[] = $instance['display'][$context]['weight'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Collect weights for extra fields.
|
|
|
|
foreach (field_info_extra_fields($entity_type, $bundle, $context) as $extra) {
|
|
|
|
$weights[] = $extra['weight'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let other modules feedback about their own additions.
|
|
|
|
$weights = array_merge($weights, module_invoke_all('field_info_max_weight', $entity_type, $bundle, $context));
|
|
|
|
$max_weight = $weights ? max($weights) : NULL;
|
|
|
|
|
|
|
|
return $max_weight;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns a field type's default settings.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field type name.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
|
|
|
* The field type's default settings, as provided by hook_field_info(), or an
|
2009-12-04 22:46:28 +00:00
|
|
|
* empty array if type or settings are not defined.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_field_settings($type) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_field_types($type);
|
|
|
|
return isset($info['settings']) ? $info['settings'] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns a field type's default instance settings.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field type name.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
|
|
|
* The field type's default instance settings, as provided by
|
2009-12-04 22:46:28 +00:00
|
|
|
* hook_field_info(), or an empty array if type or settings are not defined.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_instance_settings($type) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_field_types($type);
|
|
|
|
return isset($info['instance_settings']) ? $info['instance_settings'] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns a field widget's default settings.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A widget type name.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* The widget type's default settings, as provided by
|
2009-12-04 22:46:28 +00:00
|
|
|
* hook_field_widget_info(), or an empty array if type or settings are
|
|
|
|
* undefined.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_widget_settings($type) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_widget_types($type);
|
|
|
|
return isset($info['settings']) ? $info['settings'] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns a field formatter's default settings.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field formatter type name.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* The formatter type's default settings, as provided by
|
2009-12-04 22:46:28 +00:00
|
|
|
* hook_field_formatter_info(), or an empty array if type or settings are
|
|
|
|
* undefined.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_formatter_settings($type) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_formatter_types($type);
|
|
|
|
return isset($info['settings']) ? $info['settings'] : array();
|
|
|
|
}
|
|
|
|
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
/**
|
2009-12-04 22:46:28 +00:00
|
|
|
* Returns a field storage type's default settings.
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field storage type name.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
* @return
|
|
|
|
* The storage type's default settings, as provided by
|
2009-12-04 22:46:28 +00:00
|
|
|
* hook_field_storage_info(), or an empty array if type or settings are
|
|
|
|
* undefined.
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
*/
|
|
|
|
function field_info_storage_settings($type) {
|
|
|
|
$info = field_info_storage_types($type);
|
|
|
|
return isset($info['settings']) ? $info['settings'] : array();
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2012-05-17 12:58:49 +00:00
|
|
|
* @} End of "defgroup field_info".
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|