You are here

function bynder_create_media_usage_entry in Bynder 7

2 calls to bynder_create_media_usage_entry()
bynder_create_media_entry in includes/bynder.browser.inc
bynder_save_image in includes/bynder.browser.inc

File

includes/bynder.browser.inc, line 195
Manages the Bynder media browser functionality

Code

function bynder_create_media_usage_entry($selected_media, $fid, $entity_id = null) {
  if (!isset($entity_id)) {
    $entity = db_select('bynder_media_entity', 'b')
      ->fields('b', [
      'id',
    ])
      ->condition('b.fid', $fid, '=')
      ->condition('b.bynder_id', $selected_media['id'], '=')
      ->execute()
      ->fetchAll();
    if (!empty($entity)) {
      $entity_id = $entity[0]->id;
    }
    else {
      return null;
    }
  }
  return db_insert('bynder_media_usage')
    ->fields(array(
    'bynder_entity_id' => $entity_id,
    'bynder_id' => $selected_media['id'],
    'fid' => $fid,
    'nid' => null,
  ))
    ->execute();
}