2009-02-03 17:30:13 +00:00
|
|
|
<?php
|
2009-02-08 21:22:59 +00:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
/**
|
|
|
|
* Clear the field info cache without clearing the field data cache.
|
|
|
|
*
|
|
|
|
* 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() {
|
2009-08-11 14:59:40 +00:00
|
|
|
_field_info_collate_types(TRUE);
|
2009-08-19 13:31:14 +00:00
|
|
|
drupal_static_reset('field_build_modes');
|
2009-08-11 14:59:40 +00:00
|
|
|
_field_info_collate_fields(TRUE);
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
|
|
|
* Collate all information on field types, widget types and related structures.
|
|
|
|
*
|
|
|
|
* @param $reset
|
|
|
|
* If TRUE, clear the cache. The information will be rebuilt from the database
|
|
|
|
* next time it is needed. Defaults to FALSE.
|
|
|
|
* @return
|
|
|
|
* If $reset is TRUE, nothing.
|
|
|
|
* If $reset is FALSE, an array containing the following elements:
|
|
|
|
*
|
|
|
|
* field types: array of hook_field_info() results, keyed by field_type.
|
|
|
|
* * label, description, settings, instance_settings, default_widget,
|
|
|
|
* default_formatter, behaviors: from hook_field_info()
|
|
|
|
* * module: the module that exposes the field type
|
|
|
|
*
|
|
|
|
* widget types: array of hook_field_widget_info() results, keyed by
|
|
|
|
* widget_type.
|
|
|
|
* * label, field types, settings, behaviors: from hook_field_widget_info()
|
|
|
|
* * module: module that exposes the widget type
|
|
|
|
*
|
|
|
|
* formatter types: array of hook_field_formatter_info() results, keyed by
|
|
|
|
* formatter_type.
|
|
|
|
* * label, field types, behaviors: from hook_field_formatter_info()
|
|
|
|
* * module: module that exposes the formatter type
|
|
|
|
|
2009-08-25 21:53:48 +00:00
|
|
|
* fieldable types: array of hook_entity_info() results, keyed by entity_type.
|
2009-02-03 17:30:13 +00:00
|
|
|
* * name, id key, revision key, bundle key, cacheable, bundles: from
|
2009-08-25 21:53:48 +00:00
|
|
|
* hook_entity_info()
|
2009-02-03 17:30:13 +00:00
|
|
|
* * module: module that exposes the entity type
|
2009-08-25 21:53:48 +00:00
|
|
|
* @TODO use entity_get_info().
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
|
|
|
function _field_info_collate_types($reset = FALSE) {
|
|
|
|
static $info;
|
|
|
|
|
|
|
|
if ($reset) {
|
|
|
|
$info = NULL;
|
|
|
|
cache_clear_all('field_info_types', 'cache_field');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($info)) {
|
|
|
|
if ($cached = cache_get('field_info_types', 'cache_field')) {
|
|
|
|
$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
|
|
|
'fieldable types' => array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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']);
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
// Populate information about 'fieldable' entities.
|
2009-08-25 21:53:48 +00:00
|
|
|
foreach (module_implements('entity_info') as $module) {
|
|
|
|
$entities = (array) module_invoke($module, 'entity_info');
|
|
|
|
foreach ($entities as $name => $entity_info) {
|
|
|
|
if (!empty($entity_info['fieldable'])) {
|
|
|
|
// Provide defaults.
|
|
|
|
$entity_info += array(
|
|
|
|
'cacheable' => TRUE,
|
2009-10-16 02:04:44 +00:00
|
|
|
'translation' => array(),
|
2009-08-25 21:53:48 +00:00
|
|
|
'bundles' => array(),
|
|
|
|
);
|
|
|
|
$entity_info['object keys'] += array(
|
|
|
|
'revision' => '',
|
|
|
|
'bundle' => '',
|
|
|
|
);
|
|
|
|
// If no bundle key provided, then we assume a single bundle, named
|
|
|
|
// after the type of the object. Make sure the bundle created
|
|
|
|
// has the human-readable name we need for bundle messages.
|
|
|
|
if (empty($entity_info['object keys']['bundle']) && empty($entity_info['bundles'])) {
|
|
|
|
$entity_info['bundles'] = array($name => array('label' => $entity_info['label']));
|
|
|
|
}
|
|
|
|
$info['fieldable types'][$name] = $entity_info;
|
|
|
|
$info['fieldable types'][$name]['module'] = $module;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-31 05:35:47 +00:00
|
|
|
drupal_alter('entity_info', $info['fieldable types']);
|
2009-02-03 17:30:13 +00:00
|
|
|
|
|
|
|
cache_set('field_info_types', $info, 'cache_field');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collate all information on existing fields and instances.
|
|
|
|
*
|
|
|
|
* @param $reset
|
2009-08-02 11:24:21 +00:00
|
|
|
* If TRUE, clear the cache. The information will be rebuilt from the
|
|
|
|
* database next time it is needed. Defaults to FALSE.
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
|
|
|
* If $reset is TRUE, nothing.
|
|
|
|
* If $reset is FALSE, an array containing the following elements:
|
2009-08-11 14:59:40 +00:00
|
|
|
* - fields: Array of existing fields, keyed by field name. This entry only
|
|
|
|
* lists non-deleted fields. Each field has an additional element,
|
|
|
|
* 'bundles', which is an array of all non-deleted instances to which the
|
|
|
|
* field is assigned.
|
|
|
|
* - fields_id: Array of existing fields, keyed by field id. This entry lists
|
|
|
|
* both deleted and non-deleted fields. The bundles element is the same as
|
|
|
|
* for 'fields'.
|
2009-10-15 12:44:36 +00:00
|
|
|
* - instances: Array of existing instances, keyed by object type, bundle
|
|
|
|
* name and field name. This entry only lists non-deleted instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
|
|
|
function _field_info_collate_fields($reset = FALSE) {
|
|
|
|
static $info;
|
|
|
|
|
|
|
|
if ($reset) {
|
|
|
|
$info = NULL;
|
|
|
|
cache_clear_all('field_info_fields', 'cache_field');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($info)) {
|
|
|
|
if ($cached = cache_get('field_info_fields', 'cache_field')) {
|
2009-08-11 14:59:40 +00:00
|
|
|
$definitions = $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
|
|
|
);
|
2009-08-11 14:59:40 +00:00
|
|
|
cache_set('field_info_fields', $definitions, 'cache_field');
|
|
|
|
}
|
2009-02-03 17:30:13 +00:00
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
// Populate 'field_ids' with all fields.
|
|
|
|
$info['field_ids'] = array();
|
|
|
|
foreach ($definitions['field_ids'] as $key => $field) {
|
|
|
|
$info['field_ids'][$key] = $definitions['field_ids'][$key] = _field_info_prepare_field($field);
|
|
|
|
}
|
2009-08-02 11:24:21 +00:00
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
// Populate 'fields' only with non-deleted fields.
|
2009-09-05 09:57:21 +00:00
|
|
|
$info['fields'] = array();
|
2009-08-11 14:59:40 +00:00
|
|
|
foreach ($info['field_ids'] as $field) {
|
|
|
|
if (!$field['deleted']) {
|
|
|
|
$info['fields'][$field['field_name']] = $field;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
2009-08-11 14:59:40 +00:00
|
|
|
}
|
2009-02-03 17:30:13 +00:00
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
// Populate 'instances'. Only non-deleted instances are considered.
|
|
|
|
$info['instances'] = array();
|
|
|
|
foreach (field_info_bundles() as $bundle => $bundle_info) {
|
|
|
|
$info['instances'][$bundle] = array();
|
|
|
|
}
|
|
|
|
foreach ($definitions['instances'] as $instance) {
|
|
|
|
$field = $info['fields'][$instance['field_name']];
|
|
|
|
$instance = _field_info_prepare_instance($instance, $field);
|
2009-10-15 12:44:36 +00:00
|
|
|
$info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']] = $instance;
|
2009-08-11 14:59:40 +00:00
|
|
|
// 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'].
|
2009-10-15 12:44:36 +00:00
|
|
|
$info['fields'][$instance['field_name']]['bundles'][$instance['object_type']][] = $instance['bundle'];
|
|
|
|
$info['field_ids'][$instance['field_id']]['bundles'][$instance['object_type']][] = $instance['bundle'];
|
2009-10-14 14:55:12 +00:00
|
|
|
|
|
|
|
// Add storage details.
|
|
|
|
$details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field, $instance);
|
|
|
|
drupal_alter('field_storage_details', $details, $field, $instance);
|
2009-10-15 12:44:36 +00:00
|
|
|
$info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']]['storage_details'] = $details;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
2009-08-02 11:24:21 +00:00
|
|
|
/**
|
|
|
|
* Prepare a field definition for the current run-time context.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare an instance definition for the current run-time context.
|
|
|
|
*
|
|
|
|
* Since the instance was last saved or updated, a number of things might have
|
|
|
|
* changed: widgets or formatters disabled, new settings expected, new build
|
|
|
|
* modes added...
|
|
|
|
*
|
|
|
|
* @param $instance
|
|
|
|
* The raw instance structure as read from the database.
|
|
|
|
* @param $field
|
|
|
|
* The field structure for the instance.
|
|
|
|
*/
|
|
|
|
function _field_info_prepare_instance($instance, $field) {
|
|
|
|
$field_type = field_info_field_types($field['type']);
|
|
|
|
|
|
|
|
// 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-08-02 11:24:21 +00:00
|
|
|
// Fallback to default widget if widget type is not available.
|
|
|
|
if (!field_info_widget_types($instance['widget']['type'])) {
|
|
|
|
$instance['widget']['type'] = $field_type['default_widget'];
|
|
|
|
}
|
|
|
|
// Make sure all expected widget settings are present.
|
|
|
|
$instance['widget']['settings'] += field_info_widget_settings($instance['widget']['type']);
|
|
|
|
|
|
|
|
foreach ($instance['display'] as $build_mode => $display) {
|
|
|
|
if ($display['type'] != 'hidden') {
|
|
|
|
// Fallback to default formatter if formatter type is not available.
|
|
|
|
if (!field_info_formatter_types($instance['display'][$build_mode]['type'])) {
|
|
|
|
$instance['display'][$build_mode]['type'] = $field_type['default_formatter'];
|
|
|
|
}
|
|
|
|
// Make sure all expected formatter settings are present.
|
|
|
|
$instance['display'][$build_mode]['settings'] += field_info_formatter_settings($instance['display'][$build_mode]['type']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to 'full' display settings for unspecified build modes.
|
2009-10-15 12:44:36 +00:00
|
|
|
foreach (field_build_modes($instance['object_type']) as $build_mode => $label) {
|
2009-08-02 11:24:21 +00:00
|
|
|
if (!isset($instance['display'][$build_mode])) {
|
|
|
|
$instance['display'][$build_mode] = $instance['display']['full'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
|
|
|
* Helper function for determining the behavior of a widget
|
|
|
|
* with respect to a given operation.
|
|
|
|
*
|
|
|
|
* @param $op
|
|
|
|
* The name of the operation.
|
|
|
|
* Currently supported: 'default value', 'multiple values'.
|
|
|
|
* @param $instance
|
|
|
|
* The field instance array.
|
|
|
|
* @return
|
|
|
|
* 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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for determining the behavior of a formatter
|
|
|
|
* with respect to a given operation.
|
|
|
|
*
|
|
|
|
* @param $op
|
|
|
|
* The name of the operation.
|
|
|
|
* Currently supported: 'multiple values'
|
|
|
|
* @param $display
|
|
|
|
* The $instance['display'][$build_mode] array.
|
|
|
|
* @return
|
|
|
|
* FIELD_BEHAVIOR_NONE - do nothing for this operation.
|
|
|
|
* FIELD_BEHAVIOR_CUSTOM - use the formatter's callback function.
|
|
|
|
* FIELD_BEHAVIOR_DEFAULT - use field module default behavior.
|
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_behaviors_formatter($op, $display) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = field_info_formatter_types($display['type']);
|
|
|
|
return isset($info['behaviors'][$op]) ? $info['behaviors'][$op] : FIELD_BEHAVIOR_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return hook_field_info() data.
|
|
|
|
*
|
|
|
|
* @param $field_type
|
|
|
|
* (optional) A field type name. If ommitted, all field types will be
|
|
|
|
* returned.
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return hook_field_widget_info() data.
|
|
|
|
*
|
|
|
|
* @param $widget_type
|
|
|
|
* (optional) A widget type name. If ommitted, all widget types will be
|
|
|
|
* returned.
|
|
|
|
* @return
|
|
|
|
* Either a 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return hook_field_formatter_info() data.
|
|
|
|
*
|
|
|
|
* @param $formatter_type
|
|
|
|
* (optional) A formatter type name. If ommitted, all formatter types will be
|
|
|
|
* returned.
|
|
|
|
* @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
|
|
|
* Either a formatter type description, as provided by
|
|
|
|
* 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
|
|
|
/**
|
|
|
|
* Return hook_field_storage_info() data.
|
|
|
|
*
|
|
|
|
* @param $storage_type
|
|
|
|
* (optional) A storage type name. If ommitted, all storage types will be
|
|
|
|
* returned.
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* Return hook_fieldable_info() data.
|
|
|
|
*
|
|
|
|
* @param $obj_type
|
|
|
|
* (optional) A fieldable type name. If ommitted, all fieldable types will be
|
|
|
|
* returned.
|
|
|
|
* @return
|
|
|
|
* Either a fieldable type description, as provided by hook_fieldable_info(),
|
|
|
|
* or an array of all existing fieldable types, keyed by fieldable type name.
|
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_fieldable_types($obj_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_types();
|
|
|
|
$fieldable_types = $info['fieldable types'];
|
|
|
|
if ($obj_type) {
|
|
|
|
if (isset($fieldable_types[$obj_type])) {
|
|
|
|
return $fieldable_types[$obj_type];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $fieldable_types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-15 12:44:36 +00:00
|
|
|
* Return information about existing bundles.
|
|
|
|
*
|
|
|
|
* @param $obj_type
|
|
|
|
* The type of object; e.g. 'node' or 'user'.
|
|
|
|
* @return
|
|
|
|
* An array of bundles for the $obj_type keyed by bundle name,
|
|
|
|
* or, if no $obj_type was provided, the array of all existing bundles,
|
|
|
|
* keyed by object type.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_bundles($obj_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_types();
|
2009-10-15 12:44:36 +00:00
|
|
|
|
|
|
|
if ($obj_type) {
|
|
|
|
return isset($info['fieldable types'][$obj_type]['bundles']) ? $info['fieldable types'][$obj_type]['bundles'] : array();
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 12:44:36 +00:00
|
|
|
$bundles = array();
|
2009-02-03 17:30:13 +00:00
|
|
|
foreach ($info['fieldable types'] as $type => $fieldable_info) {
|
2009-10-15 12:44:36 +00:00
|
|
|
$bundles[$type] = $fieldable_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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return array of all field data, keyed by field name.
|
|
|
|
*
|
2009-10-12 05:22:57 +00:00
|
|
|
* @param $bundle_type
|
|
|
|
* (optional) The bundle type on which to filter the list of fields. In the
|
|
|
|
* case of nodes, this is the node type.
|
|
|
|
* @param $field
|
|
|
|
* (optional) A field array or name on which to filter the list.
|
|
|
|
* @param $field_type
|
|
|
|
* (optional) A field type on which to filter the list.
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
2009-02-10 16:09:00 +00:00
|
|
|
* 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.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-10-12 05:22:57 +00:00
|
|
|
function field_info_fields($bundle_type = NULL, $field = NULL, $field_type = NULL) {
|
|
|
|
// Build the list of fields to be used for retrieval.
|
|
|
|
if (isset($field)) {
|
|
|
|
if (is_string($field)) {
|
|
|
|
$field = field_info_field($field);
|
|
|
|
}
|
|
|
|
$fields = array($field['field_name'] => $field);
|
|
|
|
}
|
|
|
|
elseif (isset($bundle_type)) {
|
|
|
|
$instances = field_info_instances($bundle_type);
|
|
|
|
$fields = array();
|
|
|
|
foreach ($instances as $field_name => $instance) {
|
|
|
|
$fields[$field_name] = field_info_field($field_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$info = _field_info_collate_fields();
|
|
|
|
$fields = $info['fields'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a field type was given, filter the list down to fields of that type.
|
|
|
|
if (isset($field_type)) {
|
|
|
|
foreach ($fields as $key => $field) {
|
|
|
|
if ($field['type'] != $field_type) {
|
|
|
|
unset($fields[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return data about an individual field.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* non-deleted field.
|
2009-02-10 16:09:00 +00:00
|
|
|
* @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.
|
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();
|
|
|
|
if (isset($info['fields'][$field_name])) {
|
|
|
|
return $info['fields'][$field_name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 14:59:40 +00:00
|
|
|
/**
|
|
|
|
* Return data about an individual field by its id.
|
|
|
|
*
|
|
|
|
* @param $field_id
|
|
|
|
* The id of the field to retrieve. $field_id can refer to a
|
|
|
|
* deleted field.
|
|
|
|
* @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_by_id($field_id) {
|
|
|
|
$info = _field_info_collate_fields();
|
|
|
|
if (isset($info['field_ids'][$field_id])) {
|
|
|
|
return $info['field_ids'][$field_id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-10-15 12:44:36 +00:00
|
|
|
* Retrieve instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
2009-10-15 12:44:36 +00:00
|
|
|
* @param $obj_type
|
|
|
|
* The object 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.
|
|
|
|
* @return
|
|
|
|
* If $obj_type is not set, return all instances keyed by object type and
|
|
|
|
* bundle name. If $obj_type is set, return all instances for that object
|
|
|
|
* type, keyed by bundle name. If $obj_type and $bundle_name are set, return
|
|
|
|
* all instances for that bundle.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-10-16 02:47:16 +00:00
|
|
|
function field_info_instances($obj_type = NULL, $bundle_name = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2009-10-15 12:44:36 +00:00
|
|
|
if (!isset($obj_type)) {
|
2009-02-03 17:30:13 +00:00
|
|
|
return $info['instances'];
|
|
|
|
}
|
2009-10-15 12:44:36 +00:00
|
|
|
if (!isset($bundle_name)) {
|
|
|
|
return $info['instances'][$obj_type];
|
|
|
|
}
|
|
|
|
if (isset($info['instances'][$obj_type][$bundle_name])) {
|
|
|
|
return $info['instances'][$obj_type][$bundle_name];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of instance data for a specific field and bundle.
|
2009-10-15 12:44:36 +00:00
|
|
|
*
|
|
|
|
* @param $obj_type
|
|
|
|
* The object type for the instance.
|
|
|
|
* @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
|
|
|
*/
|
2009-10-15 12:44:36 +00:00
|
|
|
function field_info_instance($obj_type, $field_name, $bundle_name) {
|
2009-02-03 17:30:13 +00:00
|
|
|
$info = _field_info_collate_fields();
|
2009-10-15 12:44:36 +00:00
|
|
|
if (isset($info['instances'][$obj_type][$bundle_name][$field_name])) {
|
|
|
|
return $info['instances'][$obj_type][$bundle_name][$field_name];
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a field type's default settings.
|
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field type name.
|
|
|
|
* @return
|
|
|
|
* The field type's default settings, as provided by hook_field_info(), or an
|
|
|
|
* empty array.
|
|
|
|
*/
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a field type's default instance settings.
|
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field type name.
|
|
|
|
* @return
|
|
|
|
* The field type's default instance settings, as provided by
|
|
|
|
* hook_field_info(), or an empty array.
|
|
|
|
*/
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a field widget's default settings.
|
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A widget type name.
|
|
|
|
* @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
|
|
|
|
* hook_field_widget_info(), or an empty array.
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a field formatter's default settings.
|
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field formatter type name.
|
|
|
|
* @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
|
|
|
|
* hook_field_formatter_info(), or an empty array.
|
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
|
|
|
/**
|
|
|
|
* Return a field formatter's default settings.
|
|
|
|
*
|
|
|
|
* @param $type
|
|
|
|
* A field storage type name.
|
|
|
|
* @return
|
|
|
|
* The storage type's default settings, as provided by
|
|
|
|
* hook_field_storage_info(), or an empty array.
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2009-06-05 18:25:41 +00:00
|
|
|
* @} End of "defgroup field_info"
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|