You are here

function media_internet_add in D7 Media 7

Provides a form for adding media items from 3rd party sources.

1 string reference to 'media_internet_add'
media_internet_media_browser_plugin_view in modules/media_internet/media_internet.media.inc
Implements hook_media_browser_plugin_view().

File

modules/media_internet/media_internet.module, line 36

Code

function media_internet_add($form, &$form_state = array(), $types = NULL) {
  $form['embed_code'] = array(
    '#type' => 'textfield',
    '#title' => t('URL or Embed code'),
    '#description' => t('Input a url or embed code from one of the listed providers.'),
    '#attributes' => array(
      'class' => array(
        'media-add-from-url',
      ),
    ),
    // There is no standard specifying a maximum length for a URL. Internet
    // Explorer supports upto 2083 (http://support.microsoft.com/kb/208427), so
    // we assume publicly available media URLs are within this limit.
    '#maxlength' => 2083,
  );

  // @todo:
  // Add live previews back (currently broken)

  //$form['preview'] = array(

  //  '#type' => 'item',
  //  '#title' => t('Preview'),
  //  '#markup' => '<div id="media-add-from-url-preview"></div>'

  //);
  $form['#validators'] = array();
  if ($types) {
    $form['#validators']['media_file_validate_types'] = array(
      $types,
    );
  }
  $providers = array();
  foreach (media_internet_get_providers() as $key => $provider) {
    if (empty($provider['hidden']) || $provider['hidden'] != TRUE) {

      // @todo Convert this to show provider images in a nice format.
      $class = drupal_clean_css_identifier(drupal_strtolower($provider['title']));
      $providers[] = array(
        'data' => check_plain($provider['title']),
        'class' => array(
          $class,
        ),
      );
    }
  }
  $form['providers'] = array(
    '#theme' => 'item_list',
    '#title' => t('Supported providers'),
    '#items' => $providers,
    '#attributes' => array(
      'class' => array(
        'media-internet-providers',
      ),
    ),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}