You are here

function scald_dailymotion_search_form in Scald: Media Management made easy 6

Generates the search and search results form.

1 string reference to 'scald_dailymotion_search_form'
scald_dailymotion_menu in scald_dailymotion/scald_dailymotion.module
Implements hook_menu.

File

scald_dailymotion/scald_dailymotion.pages.inc, line 10
Contains form handlers for the DailyMotion search form.

Code

function scald_dailymotion_search_form($form_state) {
  $terms = $form_state['storage']['terms'];
  $form = array();
  $form['search'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#attributes' => array(
      'class' => 'container-inline',
    ),
  );
  $form['search']['search_term'] = array(
    '#type' => 'textfield',
    '#title' => t('Terms'),
    '#default_value' => $terms,
  );
  $form['search']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
    '#submit' => array(
      'scald_dailymotion_search_form_search_submit',
    ),
  );
  if (!empty($terms)) {
    $form['results'] = array(
      '#type' => 'fieldset',
      '#title' => t('Search results'),
      '#tree' => TRUE,
      '#theme' => 'scald_dailymotion_search_results_table',
    );
    $items = scald_dailymotion_feed('search', $terms);
    if (count($items)) {
      foreach ($items as $video) {
        $thumb = str_replace('large', 'small', $video->thumbnail['src']);
        $form['results'][$video->id] = array(
          'checkbox' => array(
            '#type' => 'checkbox',
          ),
          'title' => array(
            '#type' => 'item',
            '#value' => $video->title,
          ),
          'thumbnail' => array(
            '#type' => 'markup',
            '#value' => theme('image', $thumb, '', '', NULL, FALSE),
          ),
        );
      }
      $form['import'] = array(
        '#type' => 'submit',
        '#value' => t('Import'),
        '#submit' => array(
          'scald_dailymotion_search_form_submit',
        ),
      );
    }
    else {
      $form['results']['empty'] = array(
        '#type' => 'markup',
        '#value' => t('No results'),
      );
    }
  }
  return $form;
}