You are here

function date_repeat_field_show in Date 7.3

Same name and namespace in other branches
  1. 8 date_repeat_field/date_repeat_field.module \date_repeat_field_show()
  2. 7.2 date_repeat_field/date_repeat_field.module \date_repeat_field_show()

See if the user can access repeat date info for this entity.

Parameters

string $entity_type: The entity type.

string $entity: The specific entity to check (optional).

Return value

bool Return TRUE if there is at least one date field attached to this entity, and the current user has the permission 'view date repeats'.

1 string reference to 'date_repeat_field_show'
date_repeat_field_menu in date_repeat_field/date_repeat_field.module
Implements hook_menu().

File

date_repeat_field/date_repeat_field.module, line 130
Creates the option of Repeating Date fields and manages Date Repeat fields.

Code

function date_repeat_field_show($entity_type = 'node', $entity = NULL) {
  if (!user_access('view date repeats')) {
    return FALSE;
  }
  $bundle = date_get_entity_bundle($entity_type, $entity);

  // In Drupal 7.22 the field_info_field_map() function was added, which is more
  // memory-efficient in certain cases than field_info_fields().
  // @see https://drupal.org/node/1915646
  $field_map_available = version_compare(VERSION, '7.22', '>=');
  $field_list = $field_map_available ? field_info_field_map() : field_info_fields();
  foreach ($field_list as $field_name => $data) {
    if (in_array($data['type'], array(
      'date',
      'datestamp',
      'datetime',
    )) && array_key_exists($entity_type, $data['bundles']) && in_array($bundle, $data['bundles'][$entity_type])) {
      $field_info = $field_map_available ? field_info_field($field_name) : $data;
      if (date_is_repeat_field($field_info)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}