You are here

function date_repeat_entity_get_field in Date Repeat Entity 7.2

Same name and namespace in other branches
  1. 7 includes/date_repeat_entity.utility.inc \date_repeat_entity_get_field()

Returns a field for a given entity type, bundle and field machine name.

Searches database field definition for a field which is used in the $entity_type (e.g. node) and $bundle (e.g. event)

Parameters

string $entity_type: an entity type e.g. node.

string $bundle: a bundle type e.g. event.

string $name: a field machine name.

Return value

array representing a field.

2 calls to date_repeat_entity_get_field()
date_repeat_entity_entity_presave in ./date_repeat_entity.module
Implements hook_entity_presave().
date_repeat_entity_field_attach_form in ./date_repeat_entity.module
Implements hook_field_attach_form().

File

includes/date_repeat_entity.utility.inc, line 135
Contains utility functions that support operations on entities with repeating date fields.

Code

function date_repeat_entity_get_field($entity_type, $bundle, $name) {

  // Set a default value of NULL.
  $field_match = NULL;

  // Retrieve meta information about all of the fields in the database.
  $fields = field_info_fields();

  // Loop through the fields.
  foreach ($fields as $field_name => $field) {

    // Loop through the entity types associated with this field.
    foreach ($field['bundles'] as $field_entity_type => $bundles) {

      // Loop through the bundles (content types - in the case of node
      // entity types) associated with this entity type.
      foreach ($bundles as $field_bundle) {

        // If the entity type, bundle and field name passed to this function
        // are the same as the entity type and bundle of the field then
        // we have a match.
        if ($entity_type == $field_entity_type && $bundle == $field_bundle && $name == $field_name) {
          $field_match = $field;
        }
      }
    }
  }
  return $field_match;
}