' . t("A field for Vimeo videos complete with easy-to-use browser.") . '

'; break; } return $output; } /** * Implementation of hook_permission(). */ function vimeo_permission() { return array( 'administer vimeo' => array( 'title' => t('Administer Vimeo'), 'description' => t('Perform administration tasks for Vimeo fields'), ), 'insert vimeo videos' => array( 'title' => t('Insert Vimeo Videos'), ), ); } /** * Implementation of hook_menu(). */ function vimeo_menu() { $items = array(); // Admin settings $items['admin/config/vimeo'] = array( 'title' => 'Vimeo', 'page callback' => 'drupal_get_form', 'page arguments' => array('vimeo_settings'), 'access arguments' => array('administer vimeo'), ); $items['admin/config/vimeo/settings'] = array( 'title' => 'Settings', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/config/vimeo/source-list'] = array( 'title' => 'Vimeo Source List', 'page callback' => 'vimeo_source_list', 'page arguments' => array('vimeo_source_list'), 'access arguments' => array('administer vimeo'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items['admin/config/vimeo/add-new-source'] = array( 'title' => 'Add New Source', 'page callback' => 'drupal_get_form', 'page arguments' => array('vimeo_source_add'), 'access arguments' => array('administer vimeo'), 'type' => MENU_LOCAL_TASK, ); $items['admin/config/vimeo/source/%/delete'] = array( 'title callback' => 'vimeo_title_callback', 'title arguments' => array('Delete source: !name', 4), 'page callback' => 'drupal_get_form', 'page arguments' => array('vimeo_source_delete', 4), 'access arguments' => array('administer vimeo'), 'type' => MENU_CALLBACK, ); $items['admin/config/vimeo/default/%'] = array( 'title' => 'Vimeo Set Default', 'page callback' => 'vimeo_set_default', 'page arguments' => array(4), 'access arguments' => array('administer vimeo'), 'type' => MENU_CALLBACK, ); //Browser $items['vimeo/browser/%/%/%'] = array( 'title' => 'Vimeo Browser', 'page callback' => 'vimeo_browser', 'page arguments' => array(2, 3, 4), 'access arguments' => array('insert vimeo videos'), 'type' => MENU_CALLBACK, ); //Videos $items['vimeo/videos/%/%/%/%/%'] = array( 'title' => 'Vimeo Videos', 'page callback' => 'vimeo_get_videos', 'page arguments' => array(2, 3, 4, 5, 6), 'access arguments' => array('insert vimeo videos'), 'type' => MENU_CALLBACK, ); //AHAH request $items['vimeo/ahah/%/%/%/%/%'] = array( 'title' => 'Vimeo AHAH', 'page callback' => 'vimeo_ahah', 'page arguments' => array(2, 3, 4, 5, 6), 'access arguments' => array('insert vimeo videos'), 'type' => MENU_CALLBACK, ); return $items; } /** * Custom titles for certain pages. */ function vimeo_title_callback($title, $pid = NULL) { $replacements = array(); $source = vimeo_sources($pid); $replacements['!name'] = $source['type'] . ': ' . $source['name']; return t($title, $replacements); } /** * Return list of all available sources. */ function vimeo_sources($sid = NULL) { $sources = array(); $result = db_query('SELECT * FROM {vimeo_sources} ORDER BY type, name'); foreach ($result as $source) { $sources[$source->sid] = (array) $source; } if (isset($sid) && is_array($sources[$sid])) { return $sources[$sid]; } else { return $sources; } } /** * Create table of sources in Vimeo settings. */ function vimeo_source_list() { $header = array(t('Type'), t('Name'), t('Actions')); $rows = array(); foreach (vimeo_sources() as $source) { if (variable_get('vimeo_default_source', NULL) == $source['sid']) { $default = NULL; $type = '' . $source['type'] . ''; $name = '' . $source['name'] . ''; } else { $default = '    ' . l(t('Make default'), 'admin/config/vimeo/default/' . $source['sid']); $type = $source['type']; $name = $source['name']; } $row = array(); $row[] = $type; $row[] = $name; $row[] = l(t('Remove'), 'admin/config/vimeo/source/' . $source['sid'] . '/delete') . $default; $rows[] = $row; } $output = theme('table', array('header' => $header, 'rows' => $rows)); return $output; } function vimeo_set_default($sid) { variable_set('vimeo_default_source', $sid); $source = vimeo_sources($sid); drupal_set_message(t('Source default set to %name', array('%name' => $source['name']))); drupal_goto('admin/config/vimeo/source-list'); } /** * Form to add a new source. */ function vimeo_source_add($form_state) { $form['source'] = array( '#type' => 'textfield', '#title' => t('Source URL'), '#description' => t('Paste in the URL of a Vimeo: User, Album, Group or Channel.'), '#type' => 'textfield', '#required' => TRUE, '#size' => '60', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add source'), ); $form['#validate'][] = 'vimeo_source_validate'; $form['#submit'][] = 'vimeo_source_submit'; return $form; } /** * Validate source and collect data from Vimeo. */ function vimeo_source_validate($form, &$form_state) { $parts = explode('/', $form_state['values']['source']); if ($parts[3] == 'groups') { //Validate group $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/group/' . $parts[4] . '/info.php')); $name = $data['name']; $type = 'Group'; } elseif ($parts[3] == 'channels') { //Validate channel $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/channel/' . $parts[4] . '/info.php')); $name = $data['name']; $type = 'Channel'; } elseif ($parts[3] == 'album') { //Validate album $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/album/' . $parts[4] . '/info.php')); $name = $data['title']; $type = 'Album'; } else { //Validate user $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/' . $parts[3] . '/info.php')); $name = $data['display_name']; $type = 'User'; } $form_state['values']['name'] = $name; $form_state['values']['id'] = $data['id']; $form_state['values']['type'] = $type; if ($data['id'] == '') { form_set_error('source', t('Source did not validate with Vimeo.')); } } /** * Save source. */ function vimeo_source_submit($form, &$form_state) { $result = db_insert('vimeo_sources') ->fields(array( 'vid' => $form_state['values']['id'], 'type' => $form_state['values']['type'], 'name' => $form_state['values']['name'], )) ->execute(); drupal_set_message(t("%type: %name added.", array('%type' => $form_state['values']['type'], '%name' => $form_state['values']['name']))); } /** * Form to delete a source. */ function vimeo_source_delete($form, $form_state, $sid = NULL) { $source = vimeo_sources($sid); if (empty($source)) { drupal_set_message(t('The specified source was not found.'), 'error'); drupal_goto('admin/config/vimeo/source-list'); } $form = array(); $form['sid'] = array('#type' => 'value', '#value' => $sid); return confirm_form( $form, t('Are you sure you want to remove the source %name?', array('%name' => $source['name']) ), 'admin/config/vimeo/source-list', t('This action cannot be undone.'), t('Remove'), t('Cancel') ); } /** * Delete a player. */ function vimeo_source_delete_submit($form, &$form_state) { $source = vimeo_sources($form_state['values']['sid']); db_delete('vimeo_sources') ->condition('sid', $source['sid']) ->execute(); drupal_set_message(t('Source %name was removed.', array('%name' => $source['name']))); $form_state['redirect'] = 'admin/config/vimeo/source-list'; } /** * Return list of all available sources by type. */ function vimeo_sources_by_type($type = NULL) { $sources = array(); $result = db_query('SELECT * FROM {vimeo_sources} ORDER BY type, name'); foreach ($result as $source) { //Check default if (variable_get('vimeo_default_source', NULL) == $source->sid) { $source->default = ' default'; } else { $source->default = NULL; } $sources[$source->type][$source->vid] = $source; } if ($type != NULL && isset($sources[$type])) { return $sources[$type]; } else { return $sources; } } function vimeo_trim($text, $length) { if (strlen($text) > $length) { return substr($text, 0, ($length -2)) . '…'; } else { return $text; } } /** * Vimeo browser pop-up. */ function vimeo_browser($field_name, $delta, $settings) { drupal_add_js(drupal_get_path('module', 'vimeo') . '/vimeo.js'); drupal_add_css(drupal_get_path('module', 'vimeo') . '/theme/vimeo.css', array('media' => 'screen', 'preprocess' => FALSE)); print '' . drupal_get_css() . ''; print '

Users

Albums

Groups

Channels

' . t('Please select a source found to your left.') . '

' . t('Gathering image data for insert.') . '

' . t('Loading...') . '

'; print drupal_get_js() . ''; } function vimeo_get_videos($type, $id, $field_name, $delta, $settings) { $output = ''; print $output; } function vimeo_cache_source_set($type, $id) { //Create request path depending on type if ($type == 'user') { $path = NULL; } else { $path = $type . '/'; } //Get data from Vimeo.com $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/' . $path . $id . '/videos.php')); //Get cache time if (variable_get('vimeo_source_cache', 3) == 0) { $time = CACHE_TEMPORARY; } elseif (variable_get('vimeo_source_cache', 3) == '0.5') { $time = strtotime('+30 minutes'); } else { $time = strtotime('+' . variable_get('vimeo_source_cache', 3) . ' hours'); } //Set cache cache_set($type . '_' . $id, $data, 'cache_vimeo_sources', $time); return $data; } function vimeo_flush_caches() { return array('cache_vimeo_sources', 'cache_vimeo_videos'); } function vimeo_cache_source_get($type, $id) { //Manually flush cache if needed // TODO Please review the conversion of this statement to the D7 database API syntax. /* db_query("DELETE FROM {cache_vimeo_sources} WHERE expire <= UNIX_TIMESTAMP(CURRENT_TIMESTAMP)") */ db_delete('cache_vimeo_sources') ->where('expire <= UNIX_TIMESTAMP(CURRENT_TIMESTAMP)') ->execute(); //Get source data from cache, otherwise set it if (cache_get($type . '_' . $id, 'cache_vimeo_sources') != 0) { $videos = cache_get($type . '_' . $id, 'cache_vimeo_sources'); $videos = $videos->data; } else { $videos = vimeo_cache_source_set($type, $id); } return $videos; } // Curl helper function function vimeo_curl_get($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 30); $return = curl_exec($curl); curl_close($curl); return $return; } function vimeo_download_thumbnail($id, $url) { //Check if the containing folder exists -- if not, create it. $dir = 'public://vimeo-originals'; file_prepare_directory($dir, FILE_CREATE_DIRECTORY|FILE_MODIFY_PERMISSIONS); //Setup local filename $src = $dir . '/' . $id . '.jpg'; $result = drupal_http_request($url); $code = floor($result->code / 100) * 100; $types = array('image/jpeg'); if ($result->data && $code != 400 && $code != 500 && in_array($result->Content -Type, $types)) { $src = file_save_data($result->data, $src, FILE_EXISTS_REPLACE); return TRUE; } } function vimeo_cache_video_set($vid) { //Get data from Vimeo.com $data = unserialize(vimeo_curl_get('http://vimeo.com/api/v2/video/' . $vid . '.php')); $data = $data[0]; //Download large thumbnail to our server (for use with ImageCache) $i = 0; do { if ($i > 2) { $result = TRUE; drupal_set_message(t('Unable to download thumbnail from Vimeo.'), 'error'); } else { $result = vimeo_download_thumbnail($vid, $data['thumbnail_large']); $i++; } } while ($result != TRUE); //Add local thumbnail to data array $data['thumbnail_local'] = 'public://vimeo-originals/' . $vid . '.jpg'; //Flush ImageCahce //imagecache_image_flush($data['thumbnail_local']); //Get cache time if (variable_get('vimeo_video_cache', '-1') == '-1') { $time = CACHE_PERMANENT; } elseif (variable_get('vimeo_video_cache', '-1') == 0) { $time = CACHE_TEMPORARY; } else { $time = strtotime('+' . variable_get('vimeo_video_cache', '-1') . ' hours'); } //Cache video data cache_set($vid, $data, 'cache_vimeo_videos', $time); return $data; } function vimeo_cache_video_get($vid) { //Get data if cached, if not fetch and cache it $video = cache_get($vid, 'cache_vimeo_videos'); if (!empty($video)) { $video = cache_get($vid, 'cache_vimeo_videos'); $data = $video->data; } else { $data = vimeo_cache_video_set($vid); } return $data; } function vimeo_ahah($type, $field_name, $delta, $settings, $id) { if ($type == 'insert') { //Cache video data $data = vimeo_cache_video_set($id); $hash = md5(rand() * rand()); //Form data $vimeo_id = $id; //$thumb = ''; // Not sure why this hash is needed but it will break the 'tok' token. $thumb = ''; $title = $data['title']; $owner = $data['user_name']; $button = '' . t('Remove') . ' | ' . t('Refresh') . ''; } elseif ($type == 'remove') { //Form data $vimeo_id = NULL; $thumb = NULL; $title = NULL; $owner = NULL; $button = '' . t('Browse') . ''; } //Get form settings $settings = unserialize(base64_decode($settings)); //Set required if ($settings['required'] == FALSE) { $form_required = NULL; } else { $form_required = '*'; } //Set description if ($settings['description'] == '') { $form_description = NULL; } else { $form_description = '
' . $settings['description'] . '
'; } //Set title if ($settings['title'] == '') { $form_title = NULL; } else { $form_title = ''; } print '
' . $form_title . '
' . $thumb . '
' . $title . '
' . $owner . '
' . $button . '
' . $form_description . '
'; } /** * VimeoField admin settings form. */ function vimeo_settings() { $form['player'] = array( '#type' => 'fieldset', '#title' => t('Player Options'), '#description' => t('Note: You cannot override any options set by Vimeo Plus members.'), '#weight' => -2, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['player']['vimeo_width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => variable_get('vimeo_width', '640'), '#field_suffix' => 'px', '#required' => TRUE, '#size' => '10', '#description' => t('Width of the video player.'), ); $form['player']['vimeo_height'] = array( '#type' => 'textfield', '#title' => t('Height'), '#default_value' => variable_get('vimeo_height', '360'), '#field_suffix' => 'px', '#required' => TRUE, '#size' => '10', '#description' => t('Height of the video player.'), ); $form['player']['vimeo_colour'] = array( '#type' => 'textfield', '#title' => t('Colour'), '#default_value' => variable_get('vimeo_colour', '00ADEF'), '#required' => TRUE, '#size' => '10', '#field_prefix' => '#', '#description' => t("The colour to use in the video's UI controls."), ); $form['player']['vimeo_title'] = array( '#type' => 'select', '#title' => t('Title'), '#default_value' => variable_get('vimeo_title', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t("If yes, users will see the video's title."), ); $form['player']['vimeo_byline'] = array( '#type' => 'select', '#title' => t('Byline'), '#default_value' => variable_get('vimeo_byline', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t("If yes, users will see the video's byline."), ); $form['player']['vimeo_portrait'] = array( '#type' => 'select', '#title' => t('Portrait'), '#default_value' => variable_get('vimeo_portrait', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t("If yes, users will see the Vimeo user's portrait."), ); $form['player']['vimeo_fullscreen'] = array( '#type' => 'select', '#title' => t('Fullscreen'), '#default_value' => variable_get('vimeo_fullscreen', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t('If yes, users can watch videos fullscreen.'), ); $form['player']['vimeo_autoplay'] = array( '#type' => 'select', '#title' => t('Auto Play'), '#default_value' => variable_get('vimeo_autoplay', 0), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t('Video will automatically start playing on page load.'), ); $form['cache'] = array( '#type' => 'fieldset', '#title' => t('Cache Settings'), '#description' => t('Note: You can always manually refresh video data when editing individual nodes.'), '#weight' => 0, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['cache']['vimeo_source_cache'] = array( '#type' => 'select', '#title' => t('Source Cache Time'), '#default_value' => variable_get('vimeo_source_cache', 3), '#options' => array(0 => t('Temporary - Flush on Cron'), '0.5' => t('30 minutes'), 1 => t('1 hour'), 2 => t('2 hours'), 3 => t('3 hours (recommended)'), 5 => t('5 hours'), 24 => t('1 day'), 168 => t('1 week')), '#description' => t('How long until vimeo source lists automatically get updated.'), ); $form['cache']['vimeo_video_cache'] = array( '#type' => 'select', '#title' => t('Video Cache Time'), '#default_value' => variable_get('vimeo_video_cache', '-1'), '#options' => array(0 => t('Temporary (Not recommended)'), 24 => t('1 day'), 168 => t('1 week'), 744 => t('1 month'), 2232 => t('3 months'), '-1' => t('Never (recommended)')), '#description' => t('How long until vimeo video data automatically get updated.'), ); return system_settings_form($form); } /** * Implementation of hook_theme(). */ function vimeo_theme($existing, $type, $theme, $path) { //If template exists in the current theme use that instead. // if (file_exists(path_to_theme() . '/vimeo_custom_formatter.tpl.php')) { // $path = path_to_theme(); // } // else { // $path = drupal_get_path('module', 'vimeo') . '/theme'; // } return array( 'vimeo_browser' => array( 'render element' => 'element', ), 'vimeo_formatter_default' => array( 'variables' => array('id' => NULL, 'settings' => NULL), ), 'vimeo_formatter_plain' => array( 'variables' => array('id' => NULL), ), 'vimeo_formatter_custom' => array( 'variables' => array('element' => NULL), 'template' => 'vimeo_custom_formatter', 'path' => $path . '/theme', ), ); } /** * Setup variables for the insert window. * * @param array $vars */ function template_preprocess_vimeo_formatter_custom(&$vars) { $data = vimeo_cache_video_get($vars['element']['#item']['value']); //Vimeo video data $vars['video'] = $data; //Node data $vars['node'] = $vars['element']['#node']; //Vimeo player settings $vars['player']['width'] = variable_get('vimeo_width', 640); $vars['player']['height'] = variable_get('vimeo_height', 360); $vars['player']['title'] = variable_get('vimeo_title', 1); $vars['player']['byline'] = variable_get('vimeo_byline', 1); $vars['player']['portrait'] = variable_get('vimeo_portrait', 1); $vars['player']['color'] = variable_get('vimeo_colour', '00ADEF'); $vars['player']['fullscreen'] = variable_get('vimeo_fullscreen', 1); $vars['player']['autoplay'] = variable_get('vimeo_autoplay', 0); return $vars; } /** * Implementation of hook_field_info(). */ function vimeo_field_info() { return array( 'vimeo' => array( 'label' => t('Vimeo'), 'description' => t('Store vimeo video URL in the database.'), 'settings' => array(), 'instance_settings' => array(), 'default_widget' => 'vimeo_browser', 'default_formatter' => 'default', ), ); } /** * Implementation of hook_field_schema(). */ function vimeo_field_schema($field) { switch ($field['type']) { case 'vimeo' : $columns['value'] = array( 'type' => 'varchar', 'length' => 16, 'not null' => FALSE, 'sortable' => FAlSE, 'views' => FALSE ); break; } return array( 'columns' => $columns, ); } /** * Implementation of hook_field_validate(). */ function vimeo_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { if (is_array($items)) { foreach ($items as $delta => $item) { $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; if (is_array($item) && isset($item['_error_element'])) { unset($item['_error_element']); } } } } /** * Implementation of hook_field_is_empty(). */ function vimeo_field_is_empty($item, $field) { if (empty($item['value']) && (string) $item['value'] !== '0') { return TRUE; } return FALSE; } /** * Implementation of hook_field_formatter_info(). */ function vimeo_field_formatter_info() { return array( 'vimeo_default' => array( 'label' => t('Default'), 'field types' => array('vimeo'), ), 'vimeo_plain' => array( 'label' => t('Vimeo video ID'), 'field types' => array('vimeo'), ), 'vimeo_custom' => array( 'label' => t('Custom Template'), 'field types' => array('vimeo'), ), ); } /** * Implements hook_field_formatter_view(). * */ function vimeo_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); switch ($display['type']) { // The video iframe. case 'vimeo_default': foreach ($items as $delta => $item) { $element[$delta] = array( '#theme' => 'vimeo_formatter_default', '#id' => $item['value'], '#settings' => array(), ); } break; // Video ID case 'vimeo_plain': foreach ($items as $delta => $item) { // @todo add a setting to control if this should be output safe for a // HTML page or raw, which could be used as a value. $element[$delta] = array( '#theme' => 'vimeo_formatter_plain', '#id' => $item['value'], ); } break; } return $element; } /** * Theme function for 'default' vimeo field formatter. */ function theme_vimeo_formatter_default($variables) { if (!empty($variables['id'])) { $video_vid = $variables['id']; return ''; } else { // Nothing to output return ''; } } /** * Theme function for 'plain' vimeo field formatter. */ function theme_vimeo_formatter_plain($variables) { return $variables['id']; } /** * Implementation of hook_widget_info(). * * Here we indicate that the content module will handle * the default value and multiple values for these widgets. * * Callbacks can be omitted if default handing is used. * They're included here just so this module can be used * as an example for custom modules that might do things * differently. */ function vimeo_field_widget_info() { return array( 'vimeo_browser' => array( 'label' => t('Vimeo Browser'), 'field types' => array('vimeo'), 'behaviors' => array( 'multiple values' => FIELD_BEHAVIOR_DEFAULT, 'default value' => FIELD_BEHAVIOR_DEFAULT, ), ), ); } /** * Implementation of hook_element_info(). * * Any FAPI callbacks needed for individual widgets can be declared here, * and the element will be passed to those callbacks for processing. * * Drupal will automatically theme the element using a theme with * the same name as the hook_elements key. * * Autocomplete_path is not used by vimeo_widget but other widgets can use it * (see nodereference and userreference). */ function vimeo_element_info() { return array( 'vimeo_browser' => array( '#input' => TRUE, '#process' => array('vimeo_browser_process'), '#autocomplete_path' => FALSE, ), ); } /** * Implementation of hook_field_widget_form(). */ function vimeo_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { $element = array( '#type' => $instance['widget']['type'], '#default_value' => isset($items[$delta]) ? $items[$delta] : '', ); return $element; } /** * Process an individual element. * * Build the form element. When creating a form using FAPI #process, * note that $element['#value'] is already set. * * The $fields array is in $form['#field_info'][$element['#field_name']]. */ function vimeo_browser_process($element, $form_state, $complete_form) { drupal_add_js(drupal_get_path('module', 'vimeo') . '/vimeo.js'); drupal_add_css(drupal_get_path('module', 'vimeo') . '/theme/vimeo.css', array('media' => 'screen', 'preprocess' => FALSE)); if (module_exists('jquery_ui')) { drupal_add_library('system', 'ui.dialog'); } // Probably won't work in all cases... but I'm hoping it will $field = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['field']; $instance = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['instance']; $field_name = explode('_', $field['field_name']); $settings = array(); $settings['title'] = $instance['label']; $settings['description'] = $instance['description']; $settings['required'] = $instance['required']; $settings = base64_encode(serialize($settings)); //Get data if available $field_key = 'value'; if (isset($element['#value'][$field_key])) { $data = vimeo_cache_video_get($element['#value'][$field_key]); //$hash = md5(rand() * rand()); $button = '' . t('Remove') . ' | ' . t('Refresh') . ''; //$thumb = ''; $thumb = ''; $title = $data['title']; $owner = $data['user_name']; $vid = $element['#value'][$field_key]; } else { $button = '' . t('Browse') . ''; $thumb = NULL; $title = NULL; $owner = NULL; $vid = NULL; } //Vimeo video ID $element[$field_key] = array( '#type' => 'textfield', '#default_value' => $vid, '#autocomplete_path' => $element['#autocomplete_path'], '#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60, '#attributes' => array('class' => array('vimeo-field-id')), '#field_prefix' => '
' . $thumb . '
', '#field_suffix' => '
' . $title .'
' . $owner . '
' . $button . '
', '#prefix' => '
', '#suffix' => '
', // The following values were set by the content module and need // to be passed down to the nested element. '#title' => $instance['label'], '#description' => $instance['description'], '#required' => $instance['required'], '#field_name' => $field['field_name'], '#type_name' => $field['type'], '#delta' => $element['#parents'][2], '#columns' => $field['columns'], ); // Used so that hook_field('validate') knows where to flag an error. $element['_error_element'] = array( '#type' => 'value', '#value' => implode('][', array_merge($element['#parents'], array($field_key))), ); return $element; } /** * FAPI theme for an individual vimeo elements. * * The vimeofield or vimeoarea is already rendered by the * vimeofield or vimeoarea themes and the html output * lives in $element['#children']. Override this theme to * make custom changes to the output. * * $element['#field_name'] contains the field name * $element['#delta] is the position of this element in the group */ function theme_vimeo_browser($element) { return drupal_render($element); } /** * Implements hook_image_default_styles(). */ function vimeo_image_default_styles() { $styles = array(); $styles['vimeo_thumbnail'] = array( 'label' => 'VIMEO thumbnail', 'effects' => array( array( 'name' => 'image_scale_and_crop', 'weight' => '1', 'data' => array( 'width' => 160, 'height' => 90, 'upscale' => 0, ), ), ), ); return $styles; }