You are here

function emvideo_emfield_field_extra in Embedded Media Field 6.2

Implements hook_emfield_field_extra(). This is called on field operations to allow us to act on emvideos.

File

contrib/emvideo/emvideo.module, line 744
Embedded Video module is a handler for 3rd party video files.

Code

function emvideo_emfield_field_extra($op, &$node, $field, &$items, $teaser, $page, $module) {
  switch ($op) {
    case 'validate':

      // Title and Description should be optional.
      break;
    case 'insert':
    case 'update':

      // Called before content.module defaults.
      foreach ($items as $delta => $item) {
        if (isset($item['emvideo']['delete']) && $item['emvideo']['delete']) {
          $items[$delta]['embed'] = NULL;
          $items[$delta]['value'] = NULL;
          $items[$delta]['provider'] = NULL;
          $items[$delta]['data'] = NULL;
          $items[$delta]['embed'] = NULL;
          $items[$delta]['version'] = 0;
          $items[$delta]['duration'] = 0;
          $items[$delta]['title'] = NULL;
          $items[$delta]['description'] = NULL;
        }
        else {

          // Add alt text and alt title
          if (!empty($items[$delta]['emvideo']['title'])) {
            $items[$delta]['title'] = $items[$delta]['emvideo']['title'];
          }
          if (!empty($items[$delta]['emvideo']['description'])) {
            $items[$delta]['description'] = $items[$delta]['emvideo']['description'];
          }
        }
      }

      // We're saving in the data property so delete emvideo
      if (isset($items[$delta]['emvideo'])) {
        unset($items[$delta]['emvideo']);
      }

      // FIX FOR STATUS FIELD
      if (!isset($items[$delta]['status'])) {
        $items[$delta]['status'] = EMFIELD_STATUS_AVAILABLE;
      }

      // FIX FOR DATA NOT EMPTY
      if (empty($items[$delta]['data'])) {
        unset($items[$delta]['data']);
      }

      // Compact deltas.
      $items = array_values($items);
      break;
  }
}