You are here

function scald_youtube_scald_add_form in Scald YouTube 7

Implements hook_scald_add_form().

File

./scald_youtube.module, line 36
Defines a YouTube provider for Scald.

Code

function scald_youtube_scald_add_form(&$form, &$form_state) {
  $form['identifier'] = array(
    '#type' => 'textfield',
    '#title' => t('YouTube video identifier or URL'),
    '#element_validate' => array(
      'scald_youtube_validate_id',
    ),
    '#required' => TRUE,
    '#default_value' => '',
  );
  $api_key = variable_get('scald_youtube_api_key', '');
  if (!empty($api_key)) {
    $form['search'] = array(
      '#type' => 'fieldset',
      '#title' => t('Search on YouTube'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['search']['search_text'] = array(
      '#type' => 'textfield',
      '#default_value' => '',
      '#size' => 60,
      '#maxlength' => 128,
    );
    $form['search']['search_button'] = array(
      '#type' => 'submit',
      '#value' => t('Search'),
      '#weight' => 19,
      '#submit' => array(
        'scald_youtube_search_submit',
      ),
      '#limit_validation_errors' => array(
        array(
          'search_text',
        ),
      ),
      '#ajax' => array(
        'callback' => 'scald_youtube_search_callback',
        'wrapper' => 'search-results-wrapper',
        'method' => 'replace',
        'effect' => 'fade',
      ),
      '#attributes' => array(
        'class' => array(
          'search-button',
        ),
      ),
    );
    $form['search']['search_results_wrapper'] = array(
      '#tree' => FALSE,
      '#weight' => 20,
      '#prefix' => '<div id="search-results-wrapper">',
      '#suffix' => '</div>',
    );
    $form['search']['search_results_wrapper']['results'] = array(
      '#theme' => 'scald_youtube_search',
      '#videos' => array(),
      '#attached' => array(
        'js' => array(
          drupal_get_path('module', 'scald_youtube') . '/js/scald_youtube_search.js',
        ),
        'css' => array(
          drupal_get_path('module', 'scald_youtube') . '/css/scald_youtube_search.css',
        ),
      ),
    );
    $form['buttons']['next']['#attributes']['class'][] = 'continue-button';
  }
}