You are here

function brightcove_field_browse_access in Brightcove Video Connect 7.6

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.5 brightcove_field/brightcove_field.module \brightcove_field_browse_access()

Access callback for brightcove browser.

2 calls to brightcove_field_browse_access()
brightcove_video_edit_access in ./brightcove.video.inc
Menu access callback for editing a video.
_brightcove_field_video_widget_form in ./brightcove_field.video.inc
Helper function to return the video widget form.
1 string reference to 'brightcove_field_browse_access'
brightcove_menu in ./brightcove.module
Implements hook_menu().

File

./brightcove.module, line 1183
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function brightcove_field_browse_access($perm, $entity_type, $field_name, $entity_id_or_bundle = NULL, $client) {
  if (!brightcove_client_access('use', $client)) {
    return FALSE;
  }
  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, [
          $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, [
            $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;
}