You are here

function brightcove_field_validate in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.module \brightcove_field_validate()

Implements hook_field_validate().

File

./brightcove.module, line 440
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_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  switch ($instance['widget']['type']) {
    case BRIGHTCOVE_VIDEO_WIDGET:
      foreach ($items as $delta => $item) {
        if (!empty($item['brightcove_id'])) {
          $bcid = $item['bcid'];
          $client = entity_load_single('brightcove_client', $bcid);
          if ($client && (!isset($item['previous_client']) || $item['previous_client'] === $item['bcid'])) {
            $video = brightcove_load_video($item['brightcove_id'], $client);
            if (!$video || !$video
              ->getId()) {
              $errors[$field['field_name']][$langcode][$delta][] = [
                'error' => 'brightcove_field',
                'message' => t('%name: invalid video.', [
                  '%name' => t(isset($field['widget']['label']) ? $field['widget']['label'] : ''),
                ]),
              ];
            }
          }
        }
      }
      break;
    case BRIGHTCOVE_PLAYLIST_WIDGET:
      foreach ($items as $delta => $item) {
        if (!empty($item['brightcove_id']) && $item['brightcove_id'] !== BRIGHTCOVE_BCID_NONE && (!isset($item['previous_client']) || $item['previous_client'] === $item['bcid'])) {
          $playlist = brightcove_load_playlist($item['brightcove_id'], $item['bcid']);
          if (empty($playlist)) {
            $errors[$field['field_name']][$langcode][$delta][] = [
              'error' => 'brightcove_field',
              'message' => t('%name: invalid playlist.', [
                '%name' => t(isset($field['widget']['label']) ? $field['widget']['label'] : ''),
              ]),
            ];
          }
        }
      }
      break;
  }
}