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
|
|
|
|
2012-10-03 21:06:11 +00:00
|
|
|
use Drupal\Core\Cache\CacheBackendInterface;
|
2013-05-25 20:12:45 +00:00
|
|
|
use Drupal\Core\Language\Language;
|
2013-04-21 19:30:52 +00:00
|
|
|
use Drupal\field\Plugin\Core\Entity\FieldInstance;
|
|
|
|
use Drupal\field\Field;
|
2012-10-03 21:06:11 +00:00
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
|
|
|
* @defgroup field_info Field Info API
|
|
|
|
* @{
|
2012-09-27 15:44:17 +00:00
|
|
|
* Obtains information about Field API configuration.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
2012-09-27 15:44:17 +00:00
|
|
|
* 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
|
|
|
*
|
2012-09-27 15:44:17 +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-08-11 14:59:40 +00:00
|
|
|
*/
|
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');
|
2013-06-27 21:24:39 +00:00
|
|
|
drupal_static_reset('field_form_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
|
|
|
|
2013-06-25 10:27:47 +00:00
|
|
|
// Clear typed data definitions.
|
|
|
|
Drupal::typedData()->clearCachedDefinitions();
|
|
|
|
Drupal::service('plugin.manager.entity.field.field_type')->clearCachedDefinitions();
|
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
_field_info_collate_types_reset();
|
2013-04-21 19:30:52 +00:00
|
|
|
Field::fieldInfo()->flush();
|
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
|
|
|
* - '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.
|
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() {
|
2013-05-25 20:12:45 +00:00
|
|
|
$language_interface = language(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.
|
2013-06-29 10:56:53 +00:00
|
|
|
$langcode = $language_interface->id;
|
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(
|
- 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
|
|
|
);
|
|
|
|
|
- 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']);
|
|
|
|
|
2012-10-03 21:06:11 +00:00
|
|
|
cache('field')->set("field_info_types:$langcode", $info, CacheBackendInterface::CACHE_PERMANENT, array('field_info_types' => TRUE));
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:18:46 +00:00
|
|
|
/**
|
2012-09-27 15:44:17 +00:00
|
|
|
* Clears collated information on field and widget types and related structures.
|
2011-10-20 14:18:46 +00:00
|
|
|
*/
|
|
|
|
function _field_info_collate_types_reset() {
|
|
|
|
drupal_static_reset('_field_info_collate_types');
|
|
|
|
// Clear all languages.
|
2012-11-28 21:36:29 +00:00
|
|
|
cache('field')->deleteTags(array('field_info_types' => TRUE));
|
2011-10-20 14:18:46 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2013-05-19 20:02:16 +00:00
|
|
|
* @param string $op
|
|
|
|
* The name of the operation. Currently supported: 'default_value',
|
|
|
|
* 'multiple_values'.
|
|
|
|
* @param array $instance
|
2009-12-04 22:46:28 +00:00
|
|
|
* The field instance array.
|
|
|
|
*
|
2013-05-19 20:02:16 +00:00
|
|
|
* @return int
|
2009-12-04 22:46:28 +00:00
|
|
|
* 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) {
|
2013-05-19 20:02:16 +00:00
|
|
|
$info = array();
|
|
|
|
if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name'])) {
|
|
|
|
$info = field_info_widget_types($component['type']);
|
|
|
|
}
|
2012-10-06 04:45:15 +00:00
|
|
|
return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT;
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 22:11:59 +00:00
|
|
|
/**
|
|
|
|
* Returns a lightweight map of fields across bundles.
|
|
|
|
*
|
|
|
|
* The function only returns active, non deleted fields.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* An array keyed by field name. Each value is an array with two entries:
|
|
|
|
* - type: The field type.
|
|
|
|
* - bundles: The bundles in which the field appears, as an array with entity
|
|
|
|
* types as keys and the array of bundle names as values.
|
2013-04-23 14:39:00 +00:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* array(
|
|
|
|
* 'body' => array(
|
|
|
|
* 'bundles' => array(
|
|
|
|
* 'node' => array('page', 'article'),
|
|
|
|
* ),
|
|
|
|
* 'type' => 'text_with_summary',
|
|
|
|
* ),
|
|
|
|
* );
|
|
|
|
* @endcode
|
2013-06-27 12:12:11 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getFieldMap().
|
2012-09-28 22:11:59 +00:00
|
|
|
*/
|
|
|
|
function field_info_field_map() {
|
2013-04-21 19:30:52 +00:00
|
|
|
return Field::fieldInfo()->getFieldMap();
|
2012-09-28 22:11:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2013-06-25 10:27:47 +00:00
|
|
|
* Returns information about field types.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
|
|
|
* @param $field_type
|
2012-09-27 15:44:17 +00:00
|
|
|
* (optional) A field type name. If omitted, all field types will be returned.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-02-03 17:30:13 +00:00
|
|
|
* @return
|
2013-06-25 10:27:47 +00:00
|
|
|
* Either a field type definition, or an array of all existing field types,
|
|
|
|
* keyed by field type name.
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_field_types($field_type = NULL) {
|
2009-02-03 17:30:13 +00:00
|
|
|
if ($field_type) {
|
2013-06-25 10:27:47 +00:00
|
|
|
return Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-06-25 10:27:47 +00:00
|
|
|
return Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-26 19:39:39 +00:00
|
|
|
* Returns information about field widgets from AnnotatedClassDiscovery.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
2012-09-26 19:39:39 +00:00
|
|
|
* @param string $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
|
|
|
*
|
2012-09-26 19:39:39 +00:00
|
|
|
* @return array
|
|
|
|
* Either a single widget type description, as provided by class annotations,
|
|
|
|
* 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
|
|
|
if ($widget_type) {
|
2012-11-14 11:23:17 +00:00
|
|
|
return drupal_container()->get('plugin.manager.field.widget')->getDefinition($widget_type);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-11-14 11:23:17 +00:00
|
|
|
return drupal_container()->get('plugin.manager.field.widget')->getDefinitions();
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*
|
2012-10-14 06:04:15 +00:00
|
|
|
* @param string $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
|
|
|
*
|
2012-10-14 06:04:15 +00:00
|
|
|
* @return array
|
|
|
|
* Either a single formatter type description, as provided by class
|
|
|
|
* annotations, 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
|
|
|
if ($formatter_type) {
|
2012-11-14 11:23:17 +00:00
|
|
|
return drupal_container()->get('plugin.manager.field.formatter')->getDefinition($formatter_type);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-11-14 11:23:17 +00:00
|
|
|
return drupal_container()->get('plugin.manager.field.formatter')->getDefinitions();
|
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
|
|
|
/**
|
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
|
2012-09-27 15:44:17 +00:00
|
|
|
* hook_field_storage_info(), or an array of all existing storage types, keyed
|
|
|
|
* by storage type name.
|
- 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_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 all field definitions.
|
2009-02-03 17:30:13 +00:00
|
|
|
*
|
2012-09-28 22:11:59 +00:00
|
|
|
* Use of this function should be avoided when possible, since it loads and
|
|
|
|
* statically caches a potentially large array of information. Use
|
|
|
|
* field_info_field_map() instead.
|
|
|
|
*
|
|
|
|
* When iterating over the fields present in a given bundle after a call to
|
|
|
|
* field_info_instances($entity_type, $bundle), it is recommended to use
|
|
|
|
* field_info_field() on each individual field instead.
|
|
|
|
*
|
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
|
2012-09-27 15:44:17 +00:00
|
|
|
* which this field belongs, keyed by entity type.
|
2012-09-28 22:11:59 +00:00
|
|
|
*
|
|
|
|
* @see field_info_field_map()
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-11-29 06:35:47 +00:00
|
|
|
function field_info_fields() {
|
2013-04-21 19:30:52 +00:00
|
|
|
$info = Field::fieldInfo()->getFields();
|
2012-09-28 22:11:59 +00:00
|
|
|
|
2010-07-26 16:59:24 +00:00
|
|
|
$fields = array();
|
2012-09-28 22:11:59 +00:00
|
|
|
foreach ($info as $key => $field) {
|
2010-06-29 18:46:12 +00:00
|
|
|
if (!$field['deleted']) {
|
|
|
|
$fields[$field['field_name']] = $field;
|
|
|
|
}
|
|
|
|
}
|
2012-09-28 22:11:59 +00:00
|
|
|
|
2010-06-29 18:46:12 +00:00
|
|
|
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()
|
2013-06-27 12:12:11 +00:00
|
|
|
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getField($field_name).
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
2009-06-05 18:25:41 +00:00
|
|
|
function field_info_field($field_name) {
|
2013-04-21 19:30:52 +00:00
|
|
|
return Field::fieldInfo()->getField($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
|
2012-09-27 15:44:17 +00:00
|
|
|
* The ID of the field to retrieve. $field_id can refer to a deleted field,
|
|
|
|
* but not an inactive one.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2009-08-11 14:59:40 +00:00
|
|
|
* @return
|
2012-09-27 15:44:17 +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.
|
2009-12-04 22:46:28 +00:00
|
|
|
*
|
2010-03-26 17:14:46 +00:00
|
|
|
* @see field_info_field()
|
2013-06-27 12:12:11 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getFieldById($field_id).
|
2009-08-11 14:59:40 +00:00
|
|
|
*/
|
|
|
|
function field_info_field_by_id($field_id) {
|
2013-04-21 19:30:52 +00:00
|
|
|
return Field::fieldInfo()->getFieldById($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.
|
|
|
|
*
|
2012-09-28 22:11:59 +00:00
|
|
|
* Use of this function should be avoided when possible, since it loads and
|
|
|
|
* statically caches a potentially large array of information.
|
|
|
|
*
|
|
|
|
* When iterating over the fields present in a given bundle after a call to
|
|
|
|
* field_info_instances($entity_type, $bundle), it is recommended to use
|
|
|
|
* field_info_field() on each individual field instead.
|
2010-08-01 19:49:35 +00:00
|
|
|
*
|
|
|
|
* @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()
|
2013-06-27 12:12:11 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getFields().
|
2010-08-01 19:49:35 +00:00
|
|
|
*/
|
|
|
|
function field_info_field_by_ids() {
|
2013-04-21 19:30:52 +00:00
|
|
|
return Field::fieldInfo()->getFields();
|
2010-08-01 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2012-11-14 05:14:18 +00:00
|
|
|
* Use of this function to retrieve instances across separate bundles (i.e.
|
|
|
|
* when the $bundle parameter is NULL) should be avoided when possible, since
|
|
|
|
* it loads and statically caches a potentially large array of information.
|
|
|
|
* Use field_info_field_map() instead.
|
2012-09-28 22:11:59 +00:00
|
|
|
*
|
|
|
|
* When retrieving the instances of a specific bundle (i.e. when both
|
2012-11-14 05:14:18 +00:00
|
|
|
* $entity_type and $bundle_name are provided), the function also populates a
|
2012-09-28 22:11:59 +00:00
|
|
|
* static cache with the corresponding field definitions, allowing fast
|
|
|
|
* retrieval of field_info_field() later in the request.
|
|
|
|
*
|
2010-02-11 17:44:47 +00:00
|
|
|
* @param $entity_type
|
2012-09-28 22:11:59 +00:00
|
|
|
* (optional) The entity type for which to return instances.
|
2009-02-03 17:30:13 +00:00
|
|
|
* @param $bundle_name
|
2012-09-28 22:11:59 +00:00
|
|
|
* (optional) The bundle name for which to return instances. If $entity_type
|
|
|
|
* is NULL, the $bundle_name parameter is ignored.
|
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
|
2012-09-27 15:44:17 +00:00
|
|
|
* type, keyed by bundle name. If $entity_type and $bundle_name are set,
|
|
|
|
* return all instances for that bundle.
|
2013-06-27 12:12:11 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getInstances(),
|
|
|
|
* Field::fieldInfo()->getInstances($entity_type) or
|
|
|
|
* Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name).
|
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) {
|
2013-04-21 19:30:52 +00:00
|
|
|
$cache = Field::fieldInfo();
|
2012-02-27 03:45:36 +00:00
|
|
|
|
2012-09-28 22:11:59 +00:00
|
|
|
if (!isset($entity_type)) {
|
|
|
|
return $cache->getInstances();
|
2009-10-15 12:44:36 +00:00
|
|
|
}
|
2012-09-28 22:11:59 +00:00
|
|
|
|
|
|
|
if (!isset($bundle_name)) {
|
|
|
|
return $cache->getInstances($entity_type);
|
2009-02-03 17:30:13 +00:00
|
|
|
}
|
2012-09-28 22:11:59 +00:00
|
|
|
|
|
|
|
return $cache->getBundleInstances($entity_type, $bundle_name);
|
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
|
|
|
*
|
2012-09-28 22:11:59 +00:00
|
|
|
* The function populates a static cache with all fields and instances used in
|
|
|
|
* the bundle, allowing fast retrieval of field_info_field() or
|
|
|
|
* field_info_instance() later in the request.
|
|
|
|
*
|
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.
|
2012-08-22 20:11:08 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* An associative array of instance data for the specific field and bundle;
|
|
|
|
* NULL if the instance does not exist.
|
2013-06-27 12:12:11 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* Field::fieldInfo()->getBundleInstance($entity_type, $bundle, $field_name).
|
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) {
|
2013-06-27 12:12:11 +00:00
|
|
|
return Field::fieldInfo()->getInstance($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
|
2012-09-27 15:44:17 +00:00
|
|
|
* The context for which the list of pseudo-fields is requested. Either 'form'
|
|
|
|
* or 'display'.
|
2010-08-03 23:01:14 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The array of pseudo-field elements in the bundle.
|
|
|
|
*/
|
|
|
|
function field_info_extra_fields($entity_type, $bundle, $context) {
|
2013-04-21 19:30:52 +00:00
|
|
|
$info = Field::fieldInfo()->getBundleExtraFields($entity_type, $bundle);
|
2012-09-28 22:11:59 +00:00
|
|
|
|
|
|
|
return isset($info[$context]) ? $info[$context] : array();
|
2010-08-03 23:01:14 +00:00
|
|
|
}
|
|
|
|
|
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
|
2013-06-25 10:27:47 +00:00
|
|
|
* The field type's default settings, 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_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
|
2013-06-25 10:27:47 +00:00
|
|
|
* The field type's default instance settings, 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
|
|
|
*/
|