You are here

function youtube_field_formatter_settings_form in YouTube Field 7

Implements hook_field_formatter_settings_form().

File

./youtube.module, line 296

Code

function youtube_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  if ($display['type'] == 'youtube_video') {
    $element['youtube_size'] = array(
      '#type' => 'select',
      '#title' => t('YouTube video size'),
      '#options' => youtube_size_options(),
      '#default_value' => $settings['youtube_size'],
    );
    $element['youtube_width'] = array(
      '#type' => 'textfield',
      '#title' => t('Width'),
      '#size' => 10,
      '#default_value' => $settings['youtube_width'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][youtube_size]"]' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
    $element['youtube_height'] = array(
      '#type' => 'textfield',
      '#title' => t('Height'),
      '#size' => 10,
      '#default_value' => $settings['youtube_height'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][youtube_size]"]' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
    $element['youtube_autoplay'] = array(
      '#type' => 'checkbox',
      '#title' => t('Play video automatically when loaded (autoplay).'),
      '#default_value' => $settings['youtube_autoplay'],
    );
    $element['youtube_mute'] = array(
      '#type' => 'checkbox',
      '#title' => t('Mute video by default when loaded (mute).'),
      '#default_value' => $settings['youtube_mute'],
    );
    $element['youtube_loop'] = array(
      '#type' => 'checkbox',
      '#title' => t('Loop the playback of the video (loop).'),
      '#default_value' => $settings['youtube_loop'],
    );
    $element['youtube_controls'] = array(
      '#type' => 'checkbox',
      '#title' => t('Always hide video controls (controls).'),
      '#default_value' => $settings['youtube_controls'],
    );
    $element['youtube_autohide'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide video controls after play begins (autohide).'),
      '#default_value' => $settings['youtube_autohide'],
    );
    $element['youtube_iv_load_policy'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide video annotations by default (iv_load_policy).'),
      '#default_value' => $settings['youtube_iv_load_policy'],
    );
    $element['youtube_playsinline'] = array(
      '#type' => 'checkbox',
      '#title' => t('This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS (playsinline).'),
      '#default_value' => $settings['youtube_playsinline'],
    );
    $element['youtube_allow_autoplay'] = array(
      '#type' => 'checkbox',
      '#title' => t('The autoplay feature controls access to autoplay of media requested through the HTMLMediaElement interface (allow autoplay).'),
      '#default_value' => $settings['youtube_allow_autoplay'],
    );
    $element['youtube_allow_fullscreen'] = array(
      '#type' => 'checkbox',
      '#title' => t('The fullscreen feature controls whether the requestFullscreen() method is allowed to request fullscreen (allow fullscreen).'),
      '#default_value' => $settings['youtube_allow_fullscreen'],
    );
  }
  if ($display['type'] == 'youtube_thumbnail') {
    $element['image_style'] = array(
      '#type' => 'select',
      '#title' => t('Image style'),
      '#options' => image_style_options(FALSE),
      '#default_value' => $settings['image_style'],
      '#empty_option' => t('None (original image)'),
    );

    // Option to link the thumbnail to its original node or the YouTube video.
    // Other modules add options with hook_youtube_thumbnail_link_types_alter().
    $element['image_link'] = array(
      '#title' => t('Link image to'),
      '#type' => 'select',
      '#default_value' => $settings['image_link'],
      '#empty_option' => t('Nothing'),
      '#options' => youtube_thumbnail_link_types(),
    );

    // Allow modules that add additional link types to add their own settings.
    drupal_alter('youtube_thumbnail_field_formatter_settings', $element, $instance, $settings, $field['field_name']);
  }
  if ($display['type'] == 'youtube_url') {
    $element['link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Output this field as a link'),
      '#default_value' => $settings['link'],
    );
  }
  return $element;
}