function field_info_instances

Retrieves information about field instances.

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.

When retrieving the instances of a specific bundle (i.e. when both $entity_type and $bundle_name are provided), the function also populates a static cache with the corresponding field definitions, allowing fast retrieval of field_info_field() later in the request.

Parameters

$entity_type: (optional) The entity type for which to return instances.

$bundle_name: (optional) The bundle name for which to return instances. If $entity_type is NULL, the $bundle_name parameter is ignored.

Return value

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 type, keyed by bundle name. If $entity_type and $bundle_name are set, return all instances for that bundle.

Related topics

37 calls to field_info_instances()
CommentFieldsTest::testCommentDefaultFields in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php
Tests that the default 'comment_body' field is correctly added.
DisplayOverview::form in drupal/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php
Overrides Drupal\field_ui\OverviewBase::form().
Entity::getTranslationLanguages in drupal/core/lib/Drupal/Core/Entity/Entity.php
Implements TranslatableInterface::getTranslationLanguages().
EntityFormController::submitEntityLanguage in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Handle possible entity language changes.
EntityFormControllerNG::buildEntity in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::buildEntity().

... See full list

File

drupal/core/modules/field/field.info.inc, line 424
Field Info API, providing information about available fields and field types.

Code

function field_info_instances($entity_type = NULL, $bundle_name = NULL) {
  $cache = _field_info_field_cache();
  if (!isset($entity_type)) {
    return $cache
      ->getInstances();
  }
  if (!isset($bundle_name)) {
    return $cache
      ->getInstances($entity_type);
  }
  return $cache
    ->getBundleInstances($entity_type, $bundle_name);
}