You are here

function brightcove_field_browse_access in Brightcove Video Connect 7.5

Same name and namespace in other branches
  1. 7.7 brightcove.module \brightcove_field_browse_access()
  2. 7.2 brightcove_field/brightcove_field.module \brightcove_field_browse_access()
  3. 7.3 brightcove_field/brightcove_field.module \brightcove_field_browse_access()
  4. 7.4 brightcove_field/brightcove_field.module \brightcove_field_browse_access()
  5. 7.6 brightcove.module \brightcove_field_browse_access()

Access callback for brightcove browser.

2 calls to brightcove_field_browse_access()
_brightcove_field_playlist_widget_form in brightcove_field/brightcove_field.playlist.inc
_brightcove_field_video_widget_form in brightcove_field/brightcove_field.video.inc
1 string reference to 'brightcove_field_browse_access'
brightcove_field_menu in brightcove_field/brightcove_field.module
Implementation of hook_menu().

File

brightcove_field/brightcove_field.module, line 279
Brightcove field module provides a Content Construction Kit module to developers, allowing them to browse videos in their Brightcove Studio and upload them.

Code

function brightcove_field_browse_access($perm, $entity_type, $field_name, $entity_id_or_bundle = NULL) {
  if (user_access($perm)) {
    $field = field_info_field($field_name);
    if ($entity_id_or_bundle) {
      if (is_numeric($entity_id_or_bundle)) {

        // entity id is given
        $entity = entity_load($entity_type, array(
          $entity_id_or_bundle,
        ));
        if (count($entity)) {
          $entity = array_shift($entity);
          return entity_access('update', $entity_type, $entity) && field_access('edit', $field, $entity_type);
        }
      }
      else {

        // bundle is given
        $info = entity_get_info($entity_type);
        if (!empty($info['bundles'][$entity_id_or_bundle]) && !empty($info['entity keys']['bundle'])) {
          $key = $info['entity keys']['bundle'];
          $entity = entity_create($entity_type, array(
            $key => $entity_id_or_bundle,
          ));
          return entity_access('create', $entity_type, $entity) && field_access('edit', $field, $entity_type);
        }
      }
    }
    return entity_access('create', $entity_type) && field_access('edit', $field, $entity_type);
  }
  return FALSE;
}