field.info.inc

Field Info API, providing information about available fields and field types.

File

drupal-7.x/modules/field/field.info.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Field Info API, providing information about available fields and field types.
  5. */
  6. /**
  7. * Retrieves the FieldInfo object for the current request.
  8. *
  9. * @return FieldInfo
  10. * An instance of the FieldInfo class.
  11. */
  12. function _field_info_field_cache() {
  13. // Use the advanced drupal_static() pattern, since this is called very often.
  14. static $drupal_static_fast;
  15. if (!isset($drupal_static_fast)) {
  16. $drupal_static_fast['field_info_field_cache'] = &drupal_static(__FUNCTION__);
  17. }
  18. $field_info = &$drupal_static_fast['field_info_field_cache'];
  19. if (!isset($field_info)) {
  20. // @todo The registry should save the need for an explicit include, but not
  21. // a couple upgrade tests (DisabledNodeTypeTestCase,
  22. // FilterFormatUpgradePathTestCase...) break in a strange way without it.
  23. include_once dirname(__FILE__) . '/field.info.class.inc';
  24. $field_info = new FieldInfo();
  25. }
  26. return $field_info;
  27. }
  28. /**
  29. * @defgroup field_info Field Info API
  30. * @{
  31. * Obtain information about Field API configuration.
  32. *
  33. * The Field Info API exposes information about field types, fields,
  34. * instances, bundles, widget types, display formatters, behaviors,
  35. * and settings defined by or with the Field API.
  36. *
  37. * See @link field Field API @endlink for information about the other parts of
  38. * the Field API.
  39. */
  40. /**
  41. * Clears the field info cache without clearing the field data cache.
  42. *
  43. * This is useful when deleted fields or instances are purged. We
  44. * need to remove the purged records, but no actual field data items
  45. * are affected.
  46. */
  47. function field_info_cache_clear() {
  48. drupal_static_reset('field_view_mode_settings');
  49. drupal_static_reset('field_available_languages');
  50. // @todo: Remove this when field_attach_*_bundle() bundle management
  51. // functions are moved to the entity API.
  52. entity_info_cache_clear();
  53. _field_info_collate_types(TRUE);
  54. _field_info_field_cache()->flush();
  55. }
  56. /**
  57. * Collates all information on existing fields and instances.
  58. *
  59. * Deprecated. This function is kept to ensure backwards compatibility, but has
  60. * a serious performance impact, and should be absolutely avoided.
  61. * See http://drupal.org/node/1915646.
  62. *
  63. * Use the regular field_info_*() API functions to access the information, or
  64. * field_info_cache_clear() to clear the cached data.
  65. */
  66. function _field_info_collate_fields($reset = FALSE) {
  67. if ($reset) {
  68. _field_info_field_cache()->flush();
  69. return;
  70. }
  71. $cache = _field_info_field_cache();
  72. // Collect fields, and build the array of IDs keyed by field_name.
  73. $fields = $cache->getFields();
  74. $field_ids = array();
  75. foreach ($fields as $id => $field) {
  76. if (!$field['deleted']) {
  77. $field_ids[$field['field_name']] = $id;
  78. }
  79. }
  80. // Collect extra fields for all entity types.
  81. $extra_fields = array();
  82. foreach (field_info_bundles() as $entity_type => $bundles) {
  83. foreach ($bundles as $bundle => $info) {
  84. $extra_fields[$entity_type][$bundle] = $cache->getBundleExtraFields($entity_type, $bundle);
  85. }
  86. }
  87. return array(
  88. 'fields' => $fields,
  89. 'field_ids' => $field_ids,
  90. 'instances' => $cache->getInstances(),
  91. 'extra_fields' => $extra_fields,
  92. );
  93. }
  94. /**
  95. * Collates all information on field types, widget types and related structures.
  96. *
  97. * @param $reset
  98. * If TRUE, clear the cache. The information will be rebuilt from the database
  99. * next time it is needed. Defaults to FALSE.
  100. *
  101. * @return
  102. * If $reset is TRUE, nothing.
  103. * If $reset is FALSE, an array containing the following elements:
  104. * - 'field types': Array of hook_field_info() results, keyed by field_type.
  105. * Each element has the following components: label, description, settings,
  106. * instance_settings, default_widget, default_formatter, and behaviors
  107. * from hook_field_info(), as well as module, giving the module that exposes
  108. * the field type.
  109. * - 'widget types': Array of hook_field_widget_info() results, keyed by
  110. * widget_type. Each element has the following components: label, field
  111. * types, settings, weight, and behaviors from hook_field_widget_info(),
  112. * as well as module, giving the module that exposes the widget type.
  113. * - 'formatter types': Array of hook_field_formatter_info() results, keyed by
  114. * formatter_type. Each element has the following components: label, field
  115. * types, and behaviors from hook_field_formatter_info(), as well as
  116. * module, giving the module that exposes the formatter type.
  117. * - 'storage types': Array of hook_field_storage_info() results, keyed by
  118. * storage type names. Each element has the following components: label,
  119. * description, and settings from hook_field_storage_info(), as well as
  120. * module, giving the module that exposes the storage type.
  121. * - 'fieldable types': Array of hook_entity_info() results, keyed by
  122. * entity_type. Each element has the following components: name, id key,
  123. * revision key, bundle key, cacheable, and bundles from hook_entity_info(),
  124. * as well as module, giving the module that exposes the entity type.
  125. */
  126. function _field_info_collate_types($reset = FALSE) {
  127. global $language;
  128. static $info;
  129. // The _info() hooks invoked below include translated strings, so each
  130. // language is cached separately.
  131. $langcode = $language->language;
  132. if ($reset) {
  133. $info = NULL;
  134. // Clear all languages.
  135. cache_clear_all('field_info_types:', 'cache_field', TRUE);
  136. return;
  137. }
  138. if (!isset($info)) {
  139. if ($cached = cache_get("field_info_types:$langcode", 'cache_field')) {
  140. $info = $cached->data;
  141. }
  142. else {
  143. $info = array(
  144. 'field types' => array(),
  145. 'widget types' => array(),
  146. 'formatter types' => array(),
  147. 'storage types' => array(),
  148. );
  149. // Populate field types.
  150. foreach (module_implements('field_info') as $module) {
  151. $field_types = (array) module_invoke($module, 'field_info');
  152. foreach ($field_types as $name => $field_info) {
  153. // Provide defaults.
  154. $field_info += array(
  155. 'settings' => array(),
  156. 'instance_settings' => array(),
  157. );
  158. $info['field types'][$name] = $field_info;
  159. $info['field types'][$name]['module'] = $module;
  160. }
  161. }
  162. drupal_alter('field_info', $info['field types']);
  163. // Populate widget types.
  164. foreach (module_implements('field_widget_info') as $module) {
  165. $widget_types = (array) module_invoke($module, 'field_widget_info');
  166. foreach ($widget_types as $name => $widget_info) {
  167. // Provide defaults.
  168. $widget_info += array(
  169. 'settings' => array(),
  170. );
  171. $info['widget types'][$name] = $widget_info;
  172. $info['widget types'][$name]['module'] = $module;
  173. }
  174. }
  175. drupal_alter('field_widget_info', $info['widget types']);
  176. uasort($info['widget types'], 'drupal_sort_weight');
  177. // Populate formatter types.
  178. foreach (module_implements('field_formatter_info') as $module) {
  179. $formatter_types = (array) module_invoke($module, 'field_formatter_info');
  180. foreach ($formatter_types as $name => $formatter_info) {
  181. // Provide defaults.
  182. $formatter_info += array(
  183. 'settings' => array(),
  184. );
  185. $info['formatter types'][$name] = $formatter_info;
  186. $info['formatter types'][$name]['module'] = $module;
  187. }
  188. }
  189. drupal_alter('field_formatter_info', $info['formatter types']);
  190. // Populate storage types.
  191. foreach (module_implements('field_storage_info') as $module) {
  192. $storage_types = (array) module_invoke($module, 'field_storage_info');
  193. foreach ($storage_types as $name => $storage_info) {
  194. // Provide defaults.
  195. $storage_info += array(
  196. 'settings' => array(),
  197. );
  198. $info['storage types'][$name] = $storage_info;
  199. $info['storage types'][$name]['module'] = $module;
  200. }
  201. }
  202. drupal_alter('field_storage_info', $info['storage types']);
  203. cache_set("field_info_types:$langcode", $info, 'cache_field');
  204. }
  205. }
  206. return $info;
  207. }
  208. /**
  209. * Prepares a field definition for the current run-time context.
  210. *
  211. * The functionality has moved to the FieldInfo class. This function is kept as
  212. * a backwards-compatibility layer. See http://drupal.org/node/1915646.
  213. *
  214. * @see FieldInfo::prepareField()
  215. */
  216. function _field_info_prepare_field($field) {
  217. $cache = _field_info_field_cache();
  218. return $cache->prepareField($field);
  219. }
  220. /**
  221. * Prepares an instance definition for the current run-time context.
  222. *
  223. * The functionality has moved to the FieldInfo class. This function is kept as
  224. * a backwards-compatibility layer. See http://drupal.org/node/1915646.
  225. *
  226. * @see FieldInfo::prepareInstance()
  227. */
  228. function _field_info_prepare_instance($instance, $field) {
  229. $cache = _field_info_field_cache();
  230. return $cache->prepareInstance($instance, $field['type']);
  231. }
  232. /**
  233. * Adapts display specifications to the current run-time context.
  234. *
  235. * The functionality has moved to the FieldInfo class. This function is kept as
  236. * a backwards-compatibility layer. See http://drupal.org/node/1915646.
  237. *
  238. * @see FieldInfo::prepareInstanceDisplay()
  239. */
  240. function _field_info_prepare_instance_display($field, $display) {
  241. $cache = _field_info_field_cache();
  242. return $cache->prepareInstanceDisplay($display, $field['type']);
  243. }
  244. /**
  245. * Prepares widget specifications for the current run-time context.
  246. *
  247. * The functionality has moved to the FieldInfo class. This function is kept as
  248. * a backwards-compatibility layer. See http://drupal.org/node/1915646.
  249. *
  250. * @see FieldInfo::prepareInstanceWidget()
  251. */
  252. function _field_info_prepare_instance_widget($field, $widget) {
  253. $cache = _field_info_field_cache();
  254. return $cache->prepareInstanceWidget($widget, $field['type']);
  255. }
  256. /**
  257. * Prepares 'extra fields' for the current run-time context.
  258. *
  259. * The functionality has moved to the FieldInfo class. This function is kept as
  260. * a backwards-compatibility layer. See http://drupal.org/node/1915646.
  261. *
  262. * @see FieldInfo::prepareExtraFields()
  263. */
  264. function _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle) {
  265. $cache = _field_info_field_cache();
  266. return $cache->prepareExtraFields($extra_fields, $entity_type, $bundle);
  267. }
  268. /**
  269. * Determines the behavior of a widget with respect to an operation.
  270. *
  271. * @param $op
  272. * The name of the operation. Currently supported: 'default value',
  273. * 'multiple values'.
  274. * @param $instance
  275. * The field instance array.
  276. *
  277. * @return
  278. * One of these values:
  279. * - FIELD_BEHAVIOR_NONE: Do nothing for this operation.
  280. * - FIELD_BEHAVIOR_CUSTOM: Use the widget's callback function.
  281. * - FIELD_BEHAVIOR_DEFAULT: Use field.module default behavior.
  282. */
  283. function field_behaviors_widget($op, $instance) {
  284. $info = field_info_widget_types($instance['widget']['type']);
  285. return isset($info['behaviors'][$op]) ? $info['behaviors'][$op] : FIELD_BEHAVIOR_DEFAULT;
  286. }
  287. /**
  288. * Returns information about field types from hook_field_info().
  289. *
  290. * @param $field_type
  291. * (optional) A field type name. If omitted, all field types will be
  292. * returned.
  293. *
  294. * @return
  295. * Either a field type description, as provided by hook_field_info(), or an
  296. * array of all existing field types, keyed by field type name.
  297. */
  298. function field_info_field_types($field_type = NULL) {
  299. $info = _field_info_collate_types();
  300. $field_types = $info['field types'];
  301. if ($field_type) {
  302. if (isset($field_types[$field_type])) {
  303. return $field_types[$field_type];
  304. }
  305. }
  306. else {
  307. return $field_types;
  308. }
  309. }
  310. /**
  311. * Returns information about field widgets from hook_field_widget_info().
  312. *
  313. * @param $widget_type
  314. * (optional) A widget type name. If omitted, all widget types will be
  315. * returned.
  316. *
  317. * @return
  318. * Either a single widget type description, as provided by
  319. * hook_field_widget_info(), or an array of all existing widget types, keyed
  320. * by widget type name.
  321. */
  322. function field_info_widget_types($widget_type = NULL) {
  323. $info = _field_info_collate_types();
  324. $widget_types = $info['widget types'];
  325. if ($widget_type) {
  326. if (isset($widget_types[$widget_type])) {
  327. return $widget_types[$widget_type];
  328. }
  329. }
  330. else {
  331. return $widget_types;
  332. }
  333. }
  334. /**
  335. * Returns information about field formatters from hook_field_formatter_info().
  336. *
  337. * @param $formatter_type
  338. * (optional) A formatter type name. If omitted, all formatter types will be
  339. * returned.
  340. *
  341. * @return
  342. * Either a single formatter type description, as provided by
  343. * hook_field_formatter_info(), or an array of all existing formatter types,
  344. * keyed by formatter type name.
  345. */
  346. function field_info_formatter_types($formatter_type = NULL) {
  347. $info = _field_info_collate_types();
  348. $formatter_types = $info['formatter types'];
  349. if ($formatter_type) {
  350. if (isset($formatter_types[$formatter_type])) {
  351. return $formatter_types[$formatter_type];
  352. }
  353. }
  354. else {
  355. return $formatter_types;
  356. }
  357. }
  358. /**
  359. * Returns information about field storage from hook_field_storage_info().
  360. *
  361. * @param $storage_type
  362. * (optional) A storage type name. If omitted, all storage types will be
  363. * returned.
  364. *
  365. * @return
  366. * Either a storage type description, as provided by
  367. * hook_field_storage_info(), or an array of all existing storage types,
  368. * keyed by storage type name.
  369. */
  370. function field_info_storage_types($storage_type = NULL) {
  371. $info = _field_info_collate_types();
  372. $storage_types = $info['storage types'];
  373. if ($storage_type) {
  374. if (isset($storage_types[$storage_type])) {
  375. return $storage_types[$storage_type];
  376. }
  377. }
  378. else {
  379. return $storage_types;
  380. }
  381. }
  382. /**
  383. * Returns information about existing bundles.
  384. *
  385. * @param $entity_type
  386. * The type of entity; e.g. 'node' or 'user'.
  387. *
  388. * @return
  389. * An array of bundles for the $entity_type keyed by bundle name,
  390. * or, if no $entity_type was provided, the array of all existing bundles,
  391. * keyed by entity type.
  392. */
  393. function field_info_bundles($entity_type = NULL) {
  394. $info = entity_get_info();
  395. if ($entity_type) {
  396. return isset($info[$entity_type]['bundles']) ? $info[$entity_type]['bundles'] : array();
  397. }
  398. $bundles = array();
  399. foreach ($info as $type => $entity_info) {
  400. $bundles[$type] = $entity_info['bundles'];
  401. }
  402. return $bundles;
  403. }
  404. /**
  405. * Returns a lightweight map of fields across bundles.
  406. *
  407. * The function only returns active, non deleted fields.
  408. *
  409. * @return
  410. * An array keyed by field name. Each value is an array with two entries:
  411. * - type: The field type.
  412. * - bundles: The bundles in which the field appears, as an array with entity
  413. * types as keys and the array of bundle names as values.
  414. * Example:
  415. * @code
  416. * array(
  417. * 'body' => array(
  418. * 'bundles' => array(
  419. * 'node' => array('page', 'article'),
  420. * ),
  421. * 'type' => 'text_with_summary',
  422. * ),
  423. * );
  424. * @endcode
  425. */
  426. function field_info_field_map() {
  427. $cache = _field_info_field_cache();
  428. return $cache->getFieldMap();
  429. }
  430. /**
  431. * Returns all field definitions.
  432. *
  433. * Use of this function should be avoided when possible, since it loads and
  434. * statically caches a potentially large array of information. Use
  435. * field_info_field_map() instead.
  436. *
  437. * When iterating over the fields present in a given bundle after a call to
  438. * field_info_instances($entity_type, $bundle), it is recommended to use
  439. * field_info_field() on each individual field instead.
  440. *
  441. * @return
  442. * An array of field definitions, keyed by field name. Each field has an
  443. * additional property, 'bundles', which is an array of all the bundles to
  444. * which this field belongs keyed by entity type.
  445. *
  446. * @see field_info_field_map()
  447. */
  448. function field_info_fields() {
  449. $cache = _field_info_field_cache();
  450. $info = $cache->getFields();
  451. $fields = array();
  452. foreach ($info as $key => $field) {
  453. if (!$field['deleted']) {
  454. $fields[$field['field_name']] = $field;
  455. }
  456. }
  457. return $fields;
  458. }
  459. /**
  460. * Returns data about an individual field, given a field name.
  461. *
  462. * @param $field_name
  463. * The name of the field to retrieve. $field_name can only refer to a
  464. * non-deleted, active field. For deleted fields, use
  465. * field_info_field_by_id(). To retrieve information about inactive fields,
  466. * use field_read_fields().
  467. *
  468. * @return
  469. * The field array, as returned by field_read_fields(), with an
  470. * additional element 'bundles', whose value is an array of all the bundles
  471. * this field belongs to keyed by entity type. NULL if the field was not
  472. * found.
  473. *
  474. * @see field_info_field_by_id()
  475. */
  476. function field_info_field($field_name) {
  477. $cache = _field_info_field_cache();
  478. return $cache->getField($field_name);
  479. }
  480. /**
  481. * Returns data about an individual field, given a field ID.
  482. *
  483. * @param $field_id
  484. * The id of the field to retrieve. $field_id can refer to a
  485. * deleted field, but not an inactive one.
  486. *
  487. * @return
  488. * The field array, as returned by field_read_fields(), with an
  489. * additional element 'bundles', whose value is an array of all the bundles
  490. * this field belongs to.
  491. *
  492. * @see field_info_field()
  493. */
  494. function field_info_field_by_id($field_id) {
  495. $cache = _field_info_field_cache();
  496. return $cache->getFieldById($field_id);
  497. }
  498. /**
  499. * Returns the same data as field_info_field_by_id() for every field.
  500. *
  501. * Use of this function should be avoided when possible, since it loads and
  502. * statically caches a potentially large array of information.
  503. *
  504. * When iterating over the fields present in a given bundle after a call to
  505. * field_info_instances($entity_type, $bundle), it is recommended to use
  506. * field_info_field() on each individual field instead.
  507. *
  508. * @return
  509. * An array, each key is a field ID and the values are field arrays as
  510. * returned by field_read_fields(), with an additional element 'bundles',
  511. * whose value is an array of all the bundle this field belongs to.
  512. *
  513. * @see field_info_field()
  514. * @see field_info_field_by_id()
  515. */
  516. function field_info_field_by_ids() {
  517. $cache = _field_info_field_cache();
  518. return $cache->getFields();
  519. }
  520. /**
  521. * Retrieves information about field instances.
  522. *
  523. * Use of this function to retrieve instances across separate bundles (i.e.
  524. * when the $bundle parameter is NULL) should be avoided when possible, since
  525. * it loads and statically caches a potentially large array of information. Use
  526. * field_info_field_map() instead.
  527. *
  528. * When retrieving the instances of a specific bundle (i.e. when both
  529. * $entity_type and $bundle_name are provided), the function also populates a
  530. * static cache with the corresponding field definitions, allowing fast
  531. * retrieval of field_info_field() later in the request.
  532. *
  533. * @param $entity_type
  534. * (optional) The entity type for which to return instances.
  535. * @param $bundle_name
  536. * (optional) The bundle name for which to return instances. If $entity_type
  537. * is NULL, the $bundle_name parameter is ignored.
  538. *
  539. * @return
  540. * If $entity_type is not set, return all instances keyed by entity type and
  541. * bundle name. If $entity_type is set, return all instances for that entity
  542. * type, keyed by bundle name. If $entity_type and $bundle_name are set, return
  543. * all instances for that bundle.
  544. *
  545. * @see field_info_field_map()
  546. */
  547. function field_info_instances($entity_type = NULL, $bundle_name = NULL) {
  548. $cache = _field_info_field_cache();
  549. if (!isset($entity_type)) {
  550. return $cache->getInstances();
  551. }
  552. if (!isset($bundle_name)) {
  553. return $cache->getInstances($entity_type);
  554. }
  555. return $cache->getBundleInstances($entity_type, $bundle_name);
  556. }
  557. /**
  558. * Returns an array of instance data for a specific field and bundle.
  559. *
  560. * The function populates a static cache with all fields and instances used in
  561. * the bundle, allowing fast retrieval of field_info_field() or
  562. * field_info_instance() later in the request.
  563. *
  564. * @param $entity_type
  565. * The entity type for the instance.
  566. * @param $field_name
  567. * The field name for the instance.
  568. * @param $bundle_name
  569. * The bundle name for the instance.
  570. *
  571. * @return
  572. * An associative array of instance data for the specific field and bundle;
  573. * NULL if the instance does not exist.
  574. */
  575. function field_info_instance($entity_type, $field_name, $bundle_name) {
  576. $cache = _field_info_field_cache();
  577. $info = $cache->getBundleInstances($entity_type, $bundle_name);
  578. if (isset($info[$field_name])) {
  579. return $info[$field_name];
  580. }
  581. }
  582. /**
  583. * Returns a list and settings of pseudo-field elements in a given bundle.
  584. *
  585. * If $context is 'form', an array with the following structure:
  586. * @code
  587. * array(
  588. * 'name_of_pseudo_field_component' => array(
  589. * 'label' => The human readable name of the component,
  590. * 'description' => A short description of the component content,
  591. * 'weight' => The weight of the component in edit forms,
  592. * ),
  593. * 'name_of_other_pseudo_field_component' => array(
  594. * // ...
  595. * ),
  596. * );
  597. * @endcode
  598. *
  599. * If $context is 'display', an array with the following structure:
  600. * @code
  601. * array(
  602. * 'name_of_pseudo_field_component' => array(
  603. * 'label' => The human readable name of the component,
  604. * 'description' => A short description of the component content,
  605. * // One entry per view mode, including the 'default' mode:
  606. * 'display' => array(
  607. * 'default' => array(
  608. * 'weight' => The weight of the component in displayed entities in
  609. * this view mode,
  610. * 'visible' => TRUE if the component is visible, FALSE if hidden, in
  611. * displayed entities in this view mode,
  612. * ),
  613. * 'teaser' => array(
  614. * // ...
  615. * ),
  616. * ),
  617. * ),
  618. * 'name_of_other_pseudo_field_component' => array(
  619. * // ...
  620. * ),
  621. * );
  622. * @endcode
  623. *
  624. * @param $entity_type
  625. * The type of entity; e.g. 'node' or 'user'.
  626. * @param $bundle
  627. * The bundle name.
  628. * @param $context
  629. * The context for which the list of pseudo-fields is requested. Either
  630. * 'form' or 'display'.
  631. *
  632. * @return
  633. * The array of pseudo-field elements in the bundle.
  634. */
  635. function field_info_extra_fields($entity_type, $bundle, $context) {
  636. $cache = _field_info_field_cache();
  637. $info = $cache->getBundleExtraFields($entity_type, $bundle);
  638. return isset($info[$context]) ? $info[$context] : array();
  639. }
  640. /**
  641. * Returns the maximum weight of all the components in an entity.
  642. *
  643. * This includes fields, 'extra_fields', and other components added by
  644. * third-party modules (e.g. field_group).
  645. *
  646. * @param $entity_type
  647. * The type of entity; e.g. 'node' or 'user'.
  648. * @param $bundle
  649. * The bundle name.
  650. * @param $context
  651. * The context for which the maximum weight is requested. Either 'form', or
  652. * the name of a view mode.
  653. * @return
  654. * The maximum weight of the entity's components, or NULL if no components
  655. * were found.
  656. */
  657. function field_info_max_weight($entity_type, $bundle, $context) {
  658. $weights = array();
  659. // Collect weights for fields.
  660. foreach (field_info_instances($entity_type, $bundle) as $instance) {
  661. if ($context == 'form') {
  662. $weights[] = $instance['widget']['weight'];
  663. }
  664. elseif (isset($instance['display'][$context]['weight'])) {
  665. $weights[] = $instance['display'][$context]['weight'];
  666. }
  667. }
  668. // Collect weights for extra fields.
  669. foreach (field_info_extra_fields($entity_type, $bundle, $context) as $extra) {
  670. $weights[] = $extra['weight'];
  671. }
  672. // Let other modules feedback about their own additions.
  673. $weights = array_merge($weights, module_invoke_all('field_info_max_weight', $entity_type, $bundle, $context));
  674. $max_weight = $weights ? max($weights) : NULL;
  675. return $max_weight;
  676. }
  677. /**
  678. * Returns a field type's default settings.
  679. *
  680. * @param $type
  681. * A field type name.
  682. *
  683. * @return
  684. * The field type's default settings, as provided by hook_field_info(), or an
  685. * empty array if type or settings are not defined.
  686. */
  687. function field_info_field_settings($type) {
  688. $info = field_info_field_types($type);
  689. return isset($info['settings']) ? $info['settings'] : array();
  690. }
  691. /**
  692. * Returns a field type's default instance settings.
  693. *
  694. * @param $type
  695. * A field type name.
  696. *
  697. * @return
  698. * The field type's default instance settings, as provided by
  699. * hook_field_info(), or an empty array if type or settings are not defined.
  700. */
  701. function field_info_instance_settings($type) {
  702. $info = field_info_field_types($type);
  703. return isset($info['instance_settings']) ? $info['instance_settings'] : array();
  704. }
  705. /**
  706. * Returns a field widget's default settings.
  707. *
  708. * @param $type
  709. * A widget type name.
  710. *
  711. * @return
  712. * The widget type's default settings, as provided by
  713. * hook_field_widget_info(), or an empty array if type or settings are
  714. * undefined.
  715. */
  716. function field_info_widget_settings($type) {
  717. $info = field_info_widget_types($type);
  718. return isset($info['settings']) ? $info['settings'] : array();
  719. }
  720. /**
  721. * Returns a field formatter's default settings.
  722. *
  723. * @param $type
  724. * A field formatter type name.
  725. *
  726. * @return
  727. * The formatter type's default settings, as provided by
  728. * hook_field_formatter_info(), or an empty array if type or settings are
  729. * undefined.
  730. */
  731. function field_info_formatter_settings($type) {
  732. $info = field_info_formatter_types($type);
  733. return isset($info['settings']) ? $info['settings'] : array();
  734. }
  735. /**
  736. * Returns a field storage type's default settings.
  737. *
  738. * @param $type
  739. * A field storage type name.
  740. *
  741. * @return
  742. * The storage type's default settings, as provided by
  743. * hook_field_storage_info(), or an empty array if type or settings are
  744. * undefined.
  745. */
  746. function field_info_storage_settings($type) {
  747. $info = field_info_storage_types($type);
  748. return isset($info['settings']) ? $info['settings'] : array();
  749. }
  750. /**
  751. * @} End of "defgroup field_info".
  752. */