diff --git a/oembed.module b/oembed.module index 3720f21..676c6c1 100644 --- a/oembed.module +++ b/oembed.module @@ -159,6 +159,47 @@ function oembed_theme() { } /** + * Implements hook_form_FORM_ID_alter(). + * + * Adds enabled oEmbed plugins to the list of enabled web media providers. + */ +function oembed_form_media_internet_add_alter(&$form, $form_state) { + if (isset($form['#providers'])) { + // Create an array to hold potential Internet media providers. + $providers = $form['#providers']; + + ctools_include('plugins'); + $plugins = ctools_get_plugins('oembed', 'providers'); + uasort($plugins, 'ctools_plugin_sort'); + + foreach ($plugins as $plugin) { + // A plugin with no schemes is effectively disabled. + if (!empty($plugin['scheme'])) { + // A scheme map is used to match a URL to a specific child plugin. + if (!empty($plugin['scheme map'])) { + foreach ($plugin['scheme map'] as $id => $scheme) { + // This forces the 'get child' callback to the loaded. + ctools_plugin_get_function($plugin, 'get child'); + $plugin = ctools_get_plugins('oembed', 'providers', $id); + + $providers[] = check_plain($plugin['title']); + } + } + } + } + } + + // Override the default list of providers. + if ($providers) { + // If any providers are enabled it is assumed that some kind of embed is supported. + $form['embed_code']['#title'] = t('File URL or media resource'); + $form['embed_code']['#description'] = t('Enter a URL to a file or media resource. Many media providers also support identifying media via the embed code used to embed the media into external websites.'); + + $form['embed_code']['#description'] = theme('media_internet_embed_help', array('description' => $form['embed_code']['#description'], 'supported_providers' => implode(' ', $providers))); + } +} + +/** * Returns the provider for a url. * * @param string $url