You are here

function audiofield_field_formatter_settings_form in AudioField 7

Implements hook_field_formatter_settings_form().

File

./audio.field.inc, line 262
Implement an audio field, based on the file module's file field.

Code

function audiofield_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $form = array();

  // Load settings for audiofield players.
  if ($display['type'] == 'audiofield_player') {

    // Get all the player data.
    $players = array();
    foreach (audiofield_players() as $id => $player) {
      if (isset($player['path']) && file_exists($player['path']) || isset($player['local']) && $player['local'] || isset($player['module']) && module_exists($player['module'])) {
        foreach ($player['filetypes'] as $filetype) {
          $players[$filetype][$id] = $player['name'];
        }
      }
    }

    // Info on accepted filetypes.
    $accepted_filetypes = $instance['settings']['file_extensions'];
    $form['accepted_filetypes'] = array(
      '#type' => 'container',
      '#attributes' => array(),
      '#children' => t('Field accepts file types: %filetypes', array(
        '%filetypes' => $accepted_filetypes,
      )),
    );

    // Loop over each available filetype for the field.
    foreach (preg_split('/\\s+/', $accepted_filetypes) as $filetype) {

      // Add a select box for this filetype if it exists.
      if (isset($players[$filetype])) {
        $form['audiofield_audioplayer_' . $filetype] = array(
          '#type' => 'select',
          '#title' => check_plain($filetype . ' ' . t('Audio Players')),
          '#options' => $players[$filetype],
          '#default_value' => $settings['audiofield_audioplayer_' . $filetype],
        );
      }
    }

    // Download settings.
    $form['download_link'] = array(
      '#title' => t('Display Download Link'),
      '#description' => t('This will allow users with the appropriate permissions to view a link to directly download the audio file.'),
      '#type' => 'select',
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
      '#default_value' => $settings['download_link'],
    );

    // File details settings.
    $form['display_file_details'] = array(
      '#title' => t('Display File Details'),
      '#description' => t('This will display additional details about the audio file.'),
      '#type' => 'select',
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
      '#default_value' => $settings['display_file_details'],
    );

    // Determine if the probes are installed.
    $detect_ffprobe = audiofield_accessible_ffprobe();
    $detect_getid3 = audiofield_accessible_getid3();
    $form['audiofield_detail'] = array(
      '#type' => 'fieldset',
      '#title' => t('Show details'),
      'description' => array(
        '#theme' => 'item_list',
        '#type' => 'ul',
        '#prefix' => t('These details are stored on each mp3 file either as part of the file or as ID3 tags. To display these details, one of the following tools must be installed:'),
        '#items' => array(
          t('Command line tools !ffmpeg and !ffprobe. Status: !ffprobe_status', array(
            '!ffmpeg' => l(t('ffmpeg'), 'https://www.ffmpeg.org/documentation.html'),
            '!ffprobe' => l(t('ffprobe'), 'https://www.ffmpeg.org/ffprobe.html'),
            '!ffprobe_status' => $detect_ffprobe ? t('Enabled') : t('Disabled or not fully installed'),
          )),
          t('Drupal module !getid3 and getid3 command line. Status: !getid3_status', array(
            '!getid3' => l(t('getid3'), 'https://www.drupal.org/project/getid3'),
            '!getid3_status' => $detect_getid3 ? t('Enabled') : t('Disabled or not fully installed'),
          )),
        ),
        '#suffix' => t('You can set the path for these tools on the !admin_link.', array(
          '!admin_link' => l(t('Audio Field admin page'), 'admin/config/media/audiofield'),
        )),
        '#attributes' => array(),
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
    );
    $form['audiofield_detail']['filename'] = array(
      '#type' => 'select',
      '#title' => t('Filename'),
      '#options' => array(
        '0' => t('- None -'),
        '1' => t('Filename'),
        '2' => t('Filename (remove extension)'),
        '3' => t('File extension only'),
      ),
      '#default_value' => $settings['audiofield_detail']['filename'],
    );
    $form['audiofield_detail']['filesize'] = array(
      '#type' => 'select',
      '#title' => t('Filesize'),
      '#options' => array(
        '0' => t('- None -'),
        '1' => t('Drupal format'),
        '2' => t('Row format'),
      ),
      '#default_value' => $settings['audiofield_detail']['filesize'],
    );

    // These options are only available if one of the ID3 readers is installed.
    if ($detect_getid3 || $detect_ffprobe) {
      $form['audiofield_detail']['length'] = array(
        '#type' => 'select',
        '#title' => t('Length'),
        '#options' => array(
          '0' => t('- None -'),
          '1' => t('H:m:s'),
          '2' => t('seconds'),
        ),
        '#default_value' => $settings['audiofield_detail']['length'],
      );
      $form['audiofield_detail']['codec'] = array(
        '#type' => 'select',
        '#title' => t('Codec'),
        '#options' => array(
          '0' => t('- None -'),
          '1' => t('Short name'),
          '2' => t('Long name'),
        ),
        '#default_value' => $settings['audiofield_detail']['codec'],
      );
      $form['audiofield_detail']['channelmode'] = array(
        '#type' => 'select',
        '#title' => t('Channel mode'),
        '#options' => array(
          '0' => t('- None -'),
          '1' => t('Stereo / Mono'),
        ),
        '#default_value' => $settings['audiofield_detail']['channelmode'],
      );
      $form['audiofield_detail']['samplerate'] = array(
        '#type' => 'select',
        '#title' => t('Sample rate'),
        '#options' => array(
          '0' => t('- None -'),
          '1' => t('Hz'),
        ),
        '#default_value' => $settings['audiofield_detail']['samplerate'],
      );
      $form['audiofield_detail']['bitrate'] = array(
        '#type' => 'select',
        '#title' => t('Bitrate'),
        '#options' => array(
          '0' => t('- None -'),
          'b/s' => t('b/s'),
          'bit/s' => t('bit/s'),
          'kb/s' => t('kb/s'),
          'kbit/s' => t('kbit/s'),
        ),
        '#default_value' => $settings['audiofield_detail']['bitrate'],
      );
    }
    if ($detect_getid3) {
      $form['audiofield_detail']['tags_id3'] = array(
        '#type' => 'select',
        '#title' => t('ID3 tags support'),
        '#options' => array(
          '0' => t('- None -'),
          'id3' => t('ID3 row data (id3v1 & id3v2)'),
          'title-artist' => t('Title - Artist'),
          'artist-title' => t('Artist - Title'),
          'title' => t('Title'),
          'title-year' => t('Title - Year'),
          'artist-album-title' => t('Artist - Album - Title'),
          'language' => t('Language'),
          'title-language' => t('Title - Language'),
        ),
        '#default_value' => $settings['audiofield_detail']['tags_id3'],
        '#description' => t('Limited on mp3 format'),
      );
      $form['audiofield_detail']['tags_id3_picture'] = array(
        '#type' => 'select',
        '#title' => t('Picture'),
        '#options' => array(
          '0' => t('- None -'),
          '50x50' => t('50x50 px'),
          '100x100' => t('100x100 px'),
          '150x150' => t('150x150 px'),
          '200x200' => t('200x200 px'),
          '300x300' => t('300x300 px'),
          '600x600' => t('600x600 px'),
          'original' => t('Original size'),
        ),
        '#default_value' => $settings['audiofield_detail']['tags_id3_picture'],
        '#description' => t('Limited on mp3 format'),
      );
    }
  }
  return $form;
}