You are here

function brightcove_field_browser_process in Brightcove Video Connect 7.4

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

Brightcove field form that returns the actual field to the user. Parts of this and subsequent JS taken from Nodereference Explorer. Thanks!

1 string reference to 'brightcove_field_browser_process'
brightcove_field_element_info in brightcove_field/brightcove_field.module
Implements hook_element_info().

File

brightcove_field/brightcove_field.module, line 629
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_browser_process($element, $form_state, $form) {
  $field_key = $element['#columns'][0];
  $entity_type = $form['#entity_type'];
  $entity_info = entity_get_info($entity_type);
  $eid = $form[$entity_info['entity keys']['id']]['#value'];
  $field_info = field_info_field($element['#field_name']);
  $element[$field_key] = array(
    '#type' => 'textfield',
    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '',
    '#autocomplete_path' => 'brightcove_field/autocomplete/' . $element['#field_name'] . '/' . $element['#entity_type'] . '/' . $eid,
    // The following values were set by the content module and need
    // to be passed down to the nested element.
    '#title' => $element['#title'],
    '#required' => $element['#required'],
    '#description' => $element['#description'],
    '#field_name' => $element['#field_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
    '#attributes' => array(
      'rel' => $element['#field_name'],
      'class' => array(
        'brightcove-video-field',
      ),
    ),
  );
  if (user_access('browse videos')) {

    // Button to browse videos.
    $element['actions']['browse'] = array(
      '#type' => 'brightcove_field_browse_button',
      '#id' => $element['#id'] . '-browse',
      '#attributes' => array(
        'class' => array(
          'brightcove-field-browse-button',
        ),
        'rel' => $element['#id'] . '-video-id',
      ),
      '#value' => t('Browse'),
    );
  }
  if (user_access('upload videos') && $field_info['settings']['allow_upload']) {
    $element['actions']['upload'] = array(
      '#type' => 'brightcove_field_browse_button',
      '#id' => $element['#id'] . '-upload',
      '#attributes' => array(
        'class' => array(
          'brightcove-field-upload-button',
        ),
        'rel' => $element['#id'] . '-video-id',
      ),
      '#value' => t('Upload'),
    );
  }
  $element['actions']['remove'] = array(
    '#type' => 'brightcove_field_browse_button',
    '#id' => $element['#id'] . '-remove',
    '#attributes' => array(
      'class' => array(
        'brightcove-field-remove-button',
      ),
      'rel' => $element['#id'] . '-video-id',
    ),
    '#value' => t('Remove'),
  );
  if (!isset($element['#default_value'][$field_key])) {
    $element['actions']['remove']['#attributes']['disabled'] = 'disabled';
  }
  if (empty($brightcove_field_settings[$element['#field_name']])) {
    $brightcove_field_settings[$element['#field_name']] = array(
      'brightcove_field' => array(
        $element['#field_name'] => array(
          'entity_type' => $entity_type,
          'field_name' => $element['#field_name'],
          'entity_id' => $eid,
        ),
      ),
    );
    drupal_add_js($brightcove_field_settings[$element['#field_name']], array(
      'type' => 'setting',
    ));
  }
  if (empty($element[$field_key]['#element_validate'])) {
    $element[$field_key]['#element_validate'] = array();
  }
  array_unshift($element[$field_key]['#element_validate'], 'brightcove_field_browser_video_validate');
  return $element;
}